Skip to main content

Maven build with JDK7ea on OSX Lion

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2009-08-05


I have installed JDK 7ea on my mac. Everything looked fine in the first place. Then I tried to build a maven project and got the following error:

Unable to locate the Javac Compiler in:
/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/1.7.0.jre/Contents/Home/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(
at org.apache.maven.DefaultMaven.doExecute(
at org.apache.maven.DefaultMaven.execute(
at org.apache.maven.cli.MavenCli.execute(
at org.apache.maven.cli.MavenCli.doMain(
at org.apache.maven.cli.MavenCli.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
at org.codehaus.plexus.classworlds.launcher.Launcher.main(
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure

I modified the mvn script so that is dumps its actual settings:

JAVACMD=/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/bin/java
JAVA_HOME=/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home

I also removed the symlinks from /usr/bin for java and javac and replaced them by links pointing to $JAVA_HOME/bin.

Any idea what the problem is here (besides the obvious fact that the wrong tools.jar is referenced in the compiler run)?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-10-20

I had the same problem, you can specify the path to the executable in the pom.

See here.

You can use the enviroment variables or specify a direct path. like this

<executable>"/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/bin/java"</executable>