Showing posts with label javac ant maven. Show all posts
Showing posts with label javac ant maven. Show all posts

Tuesday, March 9, 2010

Unable to find javac compiler while running Ant from Maven2.

If your maven2 pom.xml is using a plugin (maven-antrun-plugin) to run ANT build.xml and a javac task is used in it to compile source then it is very usual to get the following error.

Reason: An Ant BuildException has occured: The following error occurred while executing this line:
C:\maventest\build.xml:79: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to ..***\***\jre.

Cause: When Maven2 runs pom.xml it uses the jre (%JAVA_HOME%\jre) instead of %JAVA_HOME% and when ant build is using 'javac' task then maven2 tries to find javac in %JAVA_HOME%\jre.

Solution: Any of the following three can be used. Solution 1 is prefered.

1. Provide a property in pom.xml for maven-antrun-plugin to fork/use javac as an external process. Please see image for reference
2. In pom.xml for maven-compiler-plugin add a property to fork out the javac process.
Read more about the properties of this plugin at http://maven.apache.org/maven-1.x/plugins/java/properties.html

<properties>
<maven.compile.fork>true</maven.compile.fork>
<properties>
 
either under  element or under of  maven-compiler-plugin.
 
3. In ant build.xml at javac task use an attribue fork='true'