Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-5756

Java home output in mvn -v is misleading

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2.5, 3.3.3
    • 3.5.4
    • Command Line
    • None
    • any

    Description

      For example on my windows box, mvn -v prints the following:

      Java home: C:\Program Files (x86)\Java\jdk1.7.0_51\jre
      

      But my JAVA_HOME is actually

      > echo %JAVA_HOME%
      C:\Program Files (x86)\Java\jdk1.7.0_51
      

      In the source code, the line comes from:

      https://git-wip-us.apache.org/repos/asf?p=maven.git;a=blob;f=maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java#l63

      version.append( "Java home: " ).append( System.getProperty( "java.home", "<unknown java home>" ) ).append( ls );
      

      which is using property "java.home" to fetch java home. However, "java.home" property is not JAVA_HOME! This is explained in detail in here: http://javahowto.blogspot.fi/2006/05/javahome-vs-javahome.html

      To quote:

      What's the difference between JAVA_HOME and java.home?

      JAVA_HOME is the JDK install directory, e.g., C:\jdk5. It's meant to be set as an environment variable and referenced in Windows batch files or Unix scripts. I always have it in my Windows Control Panel and .tcsh files,along with other common environment variables. Some Java applications use the name jdk.home for this purpose, which I think is a better name. But JAVA_HOME has been used since the beginning and is now a convention.

      java.home is the JRE install directory, e.g., C:\jdk5\jre, or C:\Program Files\Java\jre1.5.0_06. Unlike JAVA_HOME, I never seen java.home as an environment variable. java.home is a build-in Java system property, whose value is the JRE install directory. Since all Java system properties are also exposed as Ant build properties, you can also use ${java.home} in build files.

      Would jre.home be a better name? Maybe, but I don't think Sun will change it.

      This is a source of constant confusion. Some stackoverflow threads to illustrate:

      http://stackoverflow.com/questions/15279586/java-home-in-maven
      http://stackoverflow.com/questions/17620531/maven-pointing-to-jre-instead-of-jdk

      The correct way to print JAVA_HOME would be to use System.getenv("JAVA_HOME"). Either that should be used or current output should be changed so it wouldn't be so misleading.

      Attachments

        Activity

          People

            michael-o Michael Osipov
            jarkkor Jarkko Rantavuori
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: