Troubleshooting
If everything works fine, we don't have to worry about troubleshooting. However, most of the time this is not the case. A Maven build could fail for many reasons—some are under your control, while others are beyond your control. Knowing proper troubleshooting tips helps you pinpoint the exact problem. The following sections list out some of the commonly used troubleshooting tips. We will expand the list as we proceed in this book.
Enabling Maven debug-level logs
Once Maven debug level logging is enabled, it will print all the actions it takes during the build process. To enable debug level logging, use the following command:
$ mvn clean install –X
Building dependency tree
If you find any issues with any dependencies 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 result 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 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 result 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=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries java.vm.version=20.65-b04-462 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=9E4F0D49-180D-45F6-B6FB-DFA2DCBF4B77 M2_HOME=/usr/share/maven/maven-3.2.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 the configuration parameters when those are not overridden at the project level configuration. This is exactly what we discussed under the convention over configuration section. If we take the same sample POM file we used before in this chapter, we can see how the effective POM file would look using the following command.
$ mvn help:effective-pom
This is also the best way to see what default values are being used by Maven. More details about the effective-pom
command are discussed in Chapter 2, Demystifying Project Object Model.
Viewing the dependency classpath
The following command lists all the JAR files and directories in the build
classpath:
$ mvn dependency:build-classpath
The following result 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