Monday, August 24, 2009

Maven gotcha: "post-integration-test" phase

In Maven, "post-integration-test" phase can be used to do test clean up, for example, to shut down Cargo after the tests finished.

If you run "maven install" then the phases would be in this order:


pre-integration-test: start Cargo (web server)
integration-test: start tests
post-integratino-test: stop Cargo


However, if you just run "maven integration-test" to run the tests directly, "post-integration-test" phase is never called, which might lead to your cleanup process not being run.

So the workaround is to bind your clean up tasks to "integration-test" itself which will be run right after the tests run during that phase.

Saturday, August 08, 2009

Maven Javadoc workaround: Unable to find package java.lang in classpath or bootclasspath

Seen this before?


Embedded error: Error rendering Maven report: Exit code: 1 - com.sun.tools.javac.util.FatalError: Fatal Error: Unable to find package java.lang in classpath or bootclasspath
at com.sun.tools.javac.comp.MemberEnter.importAll(MemberEnter.java:123)
at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:509)
at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:446)
at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:387)
at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:819)
at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:451)
at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
at com.sun.tools.javadoc.JavadocEnter.main(JavadocEnter.java:53)
at com.sun.tools.javadoc.JavadocTool.getRootDocImpl(JavadocTool.java:152)
at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:330)
at com.sun.tools.javadoc.Start.begin(Start.java:128)
at com.sun.tools.javadoc.Main.execute(Main.java:41)
at com.sun.tools.javadoc.Main.main(Main.java:31)
javadoc: error - fatal error


This error has baffled me for the last time. Though I don't understand why the plugin or javadoc would trigger this error, I found a workaround: adding rt.jar to the "bootclasspath":

<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.6</version>
<configuration>
<minmemory>128m</minmemory>
<maxmemory>512m</maxmemory>
<!-- fix error can't find java.lang package -->
<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>