Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Ant BuildException with maven-antrun-plugin ... unable to find javac compiler

I'm trying to make Maven call an ANT build for some legacy code. The ant build builds correctly through ant. However when I call it using the maven ant plugin, it fails with the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run      (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line:
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\bea\jdk150_11\jre"

My javac exists at C:\bea\jdk150_11\bin and this works for all other things. Im not sure where Maven is getting this version of JAVA_HOME. JAVA_HOME in windows environmental variables is set to C:\bea\jdk150_11\ as it should be.

The Maven code that I'm using to call the build.xml is

<build>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-plugin</artifactId>
     <version>1.6</version>

     <executions>
          <execution>
            <phase>install</phase>
            <configuration>

              <target>
    <ant antfile="../build/build.xml" target="deliver" >
    </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
   </plugins>
  </build>
like image 591
Rob McFeely Avatar asked Jan 10 '11 08:01

Rob McFeely


People also ask

How do I run an Ant script from Maven?

Action. Configure the run goal form the Maven AntRun plugin. Define any properties you wish to pass to the external Ant build, and then call the external Ant build with the ant task, specifying the antfile and target you wish to execute. To execute this external Ant build, run mvn package.

What Maven AntRun plugin does?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.

What is Ant build exception?

Constructs an exception with the given message and exception as a root cause and a location in a file. Parameters: message - A description of or information about the exception.

What are the names of build files in Ant and Maven respectively?

Maven just created 3 Ant files – build. xml, maven-build. xml and maven-build.


1 Answers

First thing: Why do you execute your ANT script in install phase and not in compile?

The second thing: Your problem may be caused by the fact that Maven executes JRE instead of JDK, despite the fact that your JAVA_HOME points to JDK. To fix this see you have to manually adjust dependencies for maven-antrun-plugin. This is just an example:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <dependencies>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.5.0</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>compile</phase>
            <configuration><target><ant/></target></configuration>
            <goals><goal>run</goal></goals>
        </execution>
    </executions>
</plugin>
like image 101
Lukasz Avatar answered Oct 13 '22 01:10

Lukasz