- Maven Essentials
- Prabath Siriwardena
- 504字
- 2021-07-30 10:11:28
Troubleshooting
If everything works fine, we should never have to worry about troubleshooting. However, most of the time this is not the case. A Maven build can fail for many reasons, some of which are under your control and also out of your control. Knowing proper troubleshooting tips helps you to pinpoint the exact problem. The following section lists some of the most used troubleshooting tips. We will expand the list as we proceed in this book.
Enabling Maven debug level logs
Once the Maven debug level logging is enabled, it will print all the actions that it takes during the build process. To enable debug level logging, use the following command:
$ mvn clean install –X
Building a dependency tree
If you find any issue with any dependency in your Maven project, the first step is to build a dependency tree. This shows where each dependency comes from. To build the dependency tree, run the following command against your project POM
file:
$ mvn dependency:tree
The following shows the truncated output of the previous command executed against the Apache Rampart project:
[INFO] -------------------------------------------------------------- [INFO] Building Rampart - Trust 1.6.1-wso2v12 [INFO] -------------------------------------------------------------- [INFO] [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ rampart-trust --- [INFO] org.apache.rampart:rampart-trust:jar:1.6.1-wso2v12 [INFO] +- org.apache.rampart:rampart-policy:jar:1.6.1-wso2v12:compile [INFO] +- org.apache.axis2:axis2-kernel:jar:1.6.1-wso2v10:compile [INFO] | +- org.apache.ws.commons.axiom:axiom-api:jar:1.2.11-wso2v4:compile (version managed from 1.2.11) [INFO] | | \- jaxen:jaxen:jar:1.1.1:compile [INFO] | +- org.apache.ws.commons.axiom:axiom-impl:jar:1.2.11-wso2v4:compile (version managed from 1.2.11) [INFO] | +- org.apache.geronimo.specs:geronimo-ws-metadata_2.0_spec:jar:1.1.2:compile [INFO] | +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile [INFO] | +- javax.servlet:servlet-api:jar:2.3:compile [INFO] | +- commons-httpclient:commons-httpclient:jar:3.1:compile [INFO] | | \- commons-codec:commons-codec:jar:1.2:compile [INFO] | +- commons-fileupload:commons-fileupload:jar:1.2:compile
Viewing all the environment variables and system properties
If you have multiple JDKs installed in your system, you may wonder what is being used by Maven. The following command will display all the environment variables and system properties set for a given Maven project:
$ mvn help:system
The following is the truncated output of the previous command:
======================Platform Properties Details==================== ===================================================================== System Properties ===================================================================== java.runtime.name=Java(TM) SE Runtime Environment sun.boot.library.path= /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib java.vm.version= 24.75-b04 awt.nativeDoubleBuffering=true gopherProxySet=false mrj.build=11M4609 java.vm.vendor=Apple Inc. java.vendor.url=http://www.apple.com/ guice.disable.misplaced.annotation.check=true path.separator=: java.vm.name=Java HotSpot(TM) 64-Bit Server VM file.encoding.pkg=sun.io sun.java.launcher=SUN_STANDARD user.country=US sun.os.patch.level=unknown ======================================================== Environment Variables ======================================================== JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home HOME=/Users/prabath TERM_SESSION_ID=C2CEFB58-4705-4C67-BE1F-9E4179F96391 M2_HOME=/usr/share/maven/maven-3.3.3/ COMMAND_MODE=unix2003 Apple_PubSub_Socket_Render=/tmp/launch-w7NZbG/Render LOGNAME=prabath USER=prabath
Viewing the effective POM file
Maven uses default values for configuration parameters when they are not overridden in the configuration. This is exactly what we discussed under the Convention over configuration section. If we take the same sample POM
file that we used before in this chapter, we can see how the effective POM
file would look using the following command. This is also the best way to see what default values are being used by Maven:
$ mvn help:effective-pom
Note
More details about the effective-pom
command are discussed in Chapter 2, Understanding the Project Object Model (POM).
Viewing the dependency classpath
The following command will list all the JAR files and directories in the build classpath
:
$ mvn dependency:build-classpath
The following shows the truncated output of the previous command executed against the Apache Rampart project:
[INFO] -------------------------------------------------------------- [INFO] Building Rampart - Trust 1.6.1-wso2v12 [INFO] -------------------------------------------------------------- [INFO] [INFO] --- maven-dependency-plugin:2.1:build-classpath (default-cli) @ rampart-trust --- [INFO] Dependencies classpath: /Users/prabath/.m2/repository/bouncycastle/bcprov-jdk14/140/bcprov-jdk14-140.jar:/Users/prabath/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar:/Users/prabath/.m2/repository/commons-codec/commons-codec/1.2/commons-codec-1.2.jar:/Users/prabath/.m2/repository/commons-collections/commons-collections/3.1/commons-collections-3.1.jar
- C# 7 and .NET Core Cookbook
- 自己動手寫搜索引擎
- Android 7編程入門經典:使用Android Studio 2(第4版)
- Java EE 7 Development with NetBeans 8
- Java 9模塊化開發:核心原則與實踐
- Java程序設計:原理與范例
- 移動界面(Web/App)Photoshop UI設計十全大補
- Swift語言實戰精講
- 青少年信息學競賽
- Learning Concurrency in Kotlin
- 利用Python進行數據分析
- Python機器學習之金融風險管理
- Practical Microservices
- 進入IT企業必讀的324個Java面試題
- Spring Data JPA從入門到精通