There are several possible workarounds. The one that I currently prefer is to exploit the fact that Maven only overrides ${java.home} but not the original ${env.JAVA_HOME}. So your <javac> task inside the antrun plugin should look like this:
<javac fork="true" executable="${env.JAVA_HOME}/bin/javac" srcdir="${final.src.dir}" destdir="${final.class.dir}">
<classpath refid="maven.dependency.classpath"/>
</javac>
In testing, the fork attribute needed to be set to true, but I don't know why.
Another workaround is to specify the location of tools.jar in the Antrun plugin's dependencies. This introduces a second problem: Mac and Linux put the tools.jar classes in different jars. For Linux, this is just in $JAVA_HOME/lib/tools.jar as you would expect, but Mac embeds these classes in classes.jar, located in $JAVA_HOME/../Classes/classes.jar. Thus you should use
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${tools.jar}</systemPath>
</dependency>
</dependencies>
<!-- Remainder of the antrun configuration and execution -->
</plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${tools.jar}</systemPath>
</dependency>
</dependencies>
<!-- Remainder of the antrun configuration and execution -->
</plugin>
Set ${tools.jar} depending on your operating system as described in the preceding paragraph. Obviously this introduces an undesirable need to either set or detect the operating system of the build.
Perhaps there is some deep reason for Maven to internally overwrite java.home, but I can't guess it. This really should be cleaned up.
2 comments:
I found this page: http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide.
I saw following statement:
${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
${java.home}../bin/java.exe
So, java.home does not overwrite JAVA_HOME. It just refers to a different thing (JRE_HOME). tools.jar is included in JDK instead of JRE. So java.home should not be used.
I guess the problem is the name (java.home) is confusing :-( Probably, jre.home is better.
Thanks Marlon - that worked for me.
Post a Comment