Section 1.7. Producing Debug Information


1.7. Producing Debug Information

By now, you may have noticed that Maven is performing a good deal of heavy lifting. If you were using Ant, you would have already had to write an Ant build.xml file and added tasks to compile, jar, and unit test. Maven is hiding a good deal of complexity, but when debugging problems, it is nice to be able to look "behind the curtain." The ability to run Maven in debug mode and to have this tool print out every last detail of a build can be essential if you need to verify that a build is doing exactly what you think it is doing.

1.7.1. How do I do that?

For this lab, refer to the previous test application. When running maven test, you will receive the following output:

java:compile:     [echo] Compiling to C:\dev\mavenbook\code\genapp\test-application/target/classes     [echo]    java:jar-resources: [...]

What is really happening during the java:compile or the java:jar-resources goals? Running maven -X test will display the full debugging output for all goals executed in a Maven build. Let's try it, and focus on the three goals listed earlier. Running maven -X test produces the following output:

[...] java:compile:     [echo] Compiling to C:\dev\mavenbook\code\genapp\test-application/target/classes     [javac] [DEBUG] fileset: Setup scanner in dir          C:\dev\mavenbook\code\genapp\test-application\src\java with          patternSet{ includes: [  ] excludes: [**/package.html] }     [javac] [VERBOSE] mdn\testapp\App.java omitted as mdn/testapp/App.class is up  to date.    java:jar-resources: [DEBUG] FileSet: Setup scanner in dir          C:\dev\mavenbook\code\genapp\test-application\src\conf with          patternSet{ includes: [*.properties] excludes: [  ] } [VERBOSE] app.properties omitted as app.properties is up to date. [...]

The output printed by the java:compile task may look familiar. It is the output of Ant's echo and javac tasks. As explained in Section 2.1, Maven frequently uses Ant tasks to perform common operations such as copying, deleting, compiling, and creating JAR files.

1.7.2. What just happened?

The two goals you have executed produce very simple debugging output. The java:compile goal simply scans the source directory for Java source newer than its associated class file. The java:jar-resources goal looks for resources to include in a JAR file. More complex tasks such as test:test will produce debugging information about the Virtual Machine and the class loader.

When Maven has a problem or a goal throws an exception, Maven will simply print a small error message telling you that an error occurred. If you need more information, and would like to see a stack trace, add the -e flag to your command line. With the -e flag, Maven will print a full stack trace when it encounters an error.



Maven. A Developer's Notebook
Maven: A Developers Notebook (Developers Notebooks)
ISBN: 0596007507
EAN: 2147483647
Year: 2003
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net