tags:

views:

508

answers:

2

I'm retrofitting bunch of existing Java projects with unified Maven build. Since each project is mature and has established Ant based build all I'm using maven-antrun-plugin to execute existing build.xml as follows:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>
                            <ant antfile="build.xml" target="compile" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

When I run mvn compile build fails with this message:

[INFO] An Ant BuildException has occured: The following error occurred 
       while executing  this line:
build.xml:175: 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 "C:\Java\jdk1.6.0_13\jre"

What puzzles me is

  1. I have JAVA_HOME=C:\Java\jdk1.6.0_13 as part of my environment setup and when mvn.bat is executed that is exactly value I'm getting, however as you see in the error message it comes up as C:\Java\jdk1.6.0_13\jre
  2. If I run ant compile everything compiles just fine

Does it mean that perhaps maven-antrun-plugin does something like set JAVA_HOME=%JAVA_HOME%\jre? I searched my batch/build files I can't find where that change occurs

+5  A: 

The trouble is that Maven2 starts the antrun plugin with the JRE not the JDK. This link contains more information, including a fix.

Drew Wills
Awesome! Exactly what I needed. Thanks, Drew
DroidIn.net
A: 

please excuse me, in that solution you mention, where do i must add that profile? when i put mvn --version this is the output: Apache Maven 2.2.1 (r801777; 2009-08-06 16:16:01-0300) Java version: 1.6.0_20 Java home: C:\Program Files\Java\jdk1.6.0_20\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 7" version: "6.1" arch: "x86" Family: "windows"

Andres
It goes inside your POM (pom.xml) file. See this section of Maven spec: http://maven.apache.org/pom.html#Profiles
DroidIn.net