This discussion is archived
4 Replies Latest reply: Jan 20, 2013 9:49 AM by jschellSomeoneStoleMyAlias RSS

Anyone where java.home is defined on Mac?

985465 Newbie
Currently Being Moderated
Hi

I have just installed JDK 1.7_11 for Mac from jdk-7u11-macosx-x64.dmg

OS is 10.8.2 Mountain Lion

Seems to be installed OK:
$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

$ which java
/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/bin/java

$ set
..
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home
..

which is set with this entry in ~/.profile
export JAVA_HOME=`/usr/libexec/java_home -v 1.7.0_11`

all good so far.

However, I'm using maven on a few projects, and when it tries to do some compiling, it picks up the location of javac by looking at the system property 'java.home'
which is currently returning as

/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre

and of course there's no javac in there

how do I get java.home to return the right location? its a read only property

any help appreciated

Andy
  • 1. Re: Anyone where java.home is defined on Mac?
    gimbal2 Guru
    Currently Being Moderated
    This is not your problem. I use Maven too, only on Windows. I have my JAVA_HOME set to a JDK, and when I print out the java.home system property it is pointing to the runtime of that JDK, just like in your case.

    So no I don't believe you - Maven is not using the java.home property to determine the location of the java compiler or it wouldn't work on my system either. Any more ideas? How did you come to the conclusion exactly?
  • 2. Re: Anyone where java.home is defined on Mac?
    985465 Newbie
    Currently Being Moderated
    curious. I came to that conclusion by running mvn in debug mode. relevant output:

    $ mvn compile -X
    Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
    Maven home: /usr/share/maven
    Java version: 1.7.0_11, vendor: Oracle Corporation
    Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac"
    ...
    [DEBUG] properties used {java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD, ....
    ...
    rsed, sun.cpu.isalist=, sun.jnu.encoding=UTF-8, file.encoding.pkg=sun.io, env.SHLVL=1, file.separator=/, java.specification.name=Java Platform API Specification, env.GROOVY_HOME=/usr/share/groovy, java.class.version=51.0, user.country=US, java.home=/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre, java.vm.info=mixed mode, env.LOGNAME=ageach, os.version=10.8.2, env.TERM_PROGRAM_VERSION=309, path.separator=:, java.vm.version=23.6-b04, env.JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home, java.awt.printerjob=sun.lwawt.macosx.CPrinterJob, env.TERM=xterm-256color, sun.io.unicode.encodin
    ...

    The mvn command above fails with these errors:

    ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project model-global: Compilation failure
    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    [ERROR] -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project model-global: Compilation failure
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:745)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:118)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

    I wonder where else Maven could be getting the compiler location from?

    A question for another forum I guess. I'd still like to know the answer to my question though. Mostly because I spent half a day searching for it, and I like to know how things work

    Andy
  • 3. Re: Anyone where java.home is defined on Mac?
    gimbal2 Guru
    Currently Being Moderated
    user8785158 wrote:
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    Very curious indeed. Maven is indeed not finding the javac command. Just to be 100% sure: when you manually run something like $JAVA_HOME/bin/javac -version you do get a proper response, right?
    I wonder where else Maven could be getting the compiler location from?
    The JAVA_HOME environmental variable; check out the mvn shell script to see that it is referenced.
    >
    A question for another forum I guess. I'd still like to know the answer to my question though. Mostly because I spent half a day searching for it, and I like to know how things work
    Indeed, I would look for a Maven mailing list or forum. Stackoverflow is far more general purpose, it should serve your purpose. If you post there, be sure to post a link to this thread so people can read what has already been discussed.
  • 4. Re: Anyone where java.home is defined on Mac?
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Figure out which script mvn is running when you type mvn.

    Edit that file to print JAVA_HOME at the beginning.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points