Maven
  1. Maven
  2. MNG-4226

Better detection of JAVA_HOME on Apple Mac OS X

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2.2
    • Component/s: Command Line
    • Labels:
      None
    • Complexity:
      Intermediate
    • Number of attachments :
      2

      Description

      On mac JAVA_HOME is detected by using the following code:

                 if [ -z "$JAVA_VERSION" ] ; then
                   JAVA_VERSION="CurrentJDK"
                 else
                   echo "Using Java version: $JAVA_VERSION"
                 fi
                 if [ -z "$JAVA_HOME" ] ; then
                   JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
                 fi
      

      But this does not work in collaboration with Using "Java preferences" to change the actual java version to use as "CurrentJDK" does not change once you update the "java applications" order.

      There is an alternative (at least on Leopard) for determining current java home that is based on Java Preferences by using an apple provided script. So, as a replacement fo rthe code above the following could be used.

                 if [ -z "$JAVA_HOME" ] ; then
                   JAVA_HOME=`/usr/libexec/java_home | tail -1`
                 fi
      

      Could also be taht this is teh first attempt and if fails use the current way of determining home.

        Issue Links

          Activity

          Hide
          Daniel Serodio added a comment -

          Yes, please apply this fix.
          JAVA_HOME=`/usr/libexec/java_home` is the proper way to set JAVA_HOME on OS X. From man java_home, I don't think the | tail -1 is needed.

          Show
          Daniel Serodio added a comment - Yes, please apply this fix. JAVA_HOME=`/usr/libexec/java_home` is the proper way to set JAVA_HOME on OS X. From man java_home , I don't think the | tail -1 is needed.
          Hide
          Rob Elliot added a comment -

          Patch to fix java version detection on OS/X so that it uses the standard Java Preferences mechanism rather than always using Java 6.

          Show
          Rob Elliot added a comment - Patch to fix java version detection on OS/X so that it uses the standard Java Preferences mechanism rather than always using Java 6.
          Hide
          Rob Elliot added a comment -

          I just wasted an evening trying to establish why setting the preferred Java version to Java 7 in Mac's Java Preferences still left Maven using Java 6, due to this issue. Ant does it the right way, via /usr/libexec/java_home. Attached is a patch.

          Show
          Rob Elliot added a comment - I just wasted an evening trying to establish why setting the preferred Java version to Java 7 in Mac's Java Preferences still left Maven using Java 6, due to this issue. Ant does it the right way, via /usr/libexec/java_home. Attached is a patch.
          Hide
          Tamás Cservenák added a comment - - edited

          You can circumvent current maven deployments (3.0.4 inclusive) without modifying them, by adding following file in /etc/mavenrc:

          JAVA_HOME=`/usr/libexec/java_home -v 1.7`
          

          Note: this will make Maven use same Java system wide!

          Show
          Tamás Cservenák added a comment - - edited You can circumvent current maven deployments (3.0.4 inclusive) without modifying them, by adding following file in /etc/mavenrc : JAVA_HOME=`/usr/libexec/java_home -v 1.7` Note: this will make Maven use same Java system wide!
          Hide
          Nikolaj Schumacher added a comment -

          This should probably be revisited soon. Apple recently removed the "Java Preferences" and has everything in the system default to Java 7, if that is installed. The pre-installed version of mvn 3.0.3 also uses Java 7, but any upgrade to 3.0.4 will revert back to Java 6 due to this issue.

          I assume this will surprise quite a few people and cost them time tracking it down. And the current hard-coded /System/Library path will probably break as soon as Apple drops their own JRE (which they deprecated in 2010.)

          Show
          Nikolaj Schumacher added a comment - This should probably be revisited soon. Apple recently removed the "Java Preferences" and has everything in the system default to Java 7, if that is installed. The pre-installed version of mvn 3.0.3 also uses Java 7, but any upgrade to 3.0.4 will revert back to Java 6 due to this issue. I assume this will surprise quite a few people and cost them time tracking it down. And the current hard-coded /System/Library path will probably break as soon as Apple drops their own JRE (which they deprecated in 2010.)
          Hide
          Christopher Tubbs added a comment -

          Uploaded new patch that preserves existing behaviour, but makes Maven work out of the box on newer OS X machines.

          See attached git formatted patch 0001-MNG-4226-Detect-JAVA_HOME-on-newer-Mac-OS-X.patch or pull request.

          Show
          Christopher Tubbs added a comment - Uploaded new patch that preserves existing behaviour, but makes Maven work out of the box on newer OS X machines. See attached git formatted patch 0001-MNG-4226-Detect-JAVA_HOME-on-newer-Mac-OS-X.patch or pull request .
          Hide
          Jason van Zyl added a comment -

          Committed on 65863e0a28298b6d95bfbbf7cc28953f6ba91f93
          Submitted by: Christopher Tubbs <ctubbsii@apache.org>
          https://github.com/apache/maven/pull/11

          Show
          Jason van Zyl added a comment - Committed on 65863e0a28298b6d95bfbbf7cc28953f6ba91f93 Submitted by: Christopher Tubbs <ctubbsii@apache.org> https://github.com/apache/maven/pull/11

            People

            • Assignee:
              Jason van Zyl
              Reporter:
              Alin Dreghiciu
            • Votes:
              12 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: