Error: JAVA_HOME is not defined correctly executing maven

前端 未结 14 1526
时光说笑
时光说笑 2020-11-28 05:50

I installed java and set path to environment and when I execute echo $JAVA_HOME I get the following output:

/usr/lib/jvm/java-7-oracle/jre/bin/j         


        
14条回答
  •  粉色の甜心
    2020-11-28 06:46

    It happens because of the reason mentioned below :

    If you see the mvn script: The code fails here ---

    Steps for debugging and fixing:

    Step 1: Open the mvn script /Users/Username/apache-maven-3.0.5/bin/mvn (Open with the less command like: less /Users/Username/apache-maven-3.0.5/bin/mvn)

    Step 2: Find out the below code in the script:

      if [ -z "$JAVACMD" ] ; then
      if [ -n "$JAVA_HOME"  ] ; then
        if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
          # IBM's JDK on AIX uses strange locations for the executables
          JAVACMD="$JAVA_HOME/jre/sh/java"
        else
          JAVACMD="$JAVA_HOME/bin/java"
        fi
      else
        JAVACMD="`which java`"
      fi
    fi
    
    if [ ! -x "$JAVACMD" ] ; then
      echo "Error: JAVA_HOME is not defined correctly."
      echo "  We cannot execute $JAVACMD"
      exit 1
    fi
    

    Step3: It is happening because JAVACMD variable was not set. So it displays the error.

    Note: To Fix it

    export JAVACMD=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java
    
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/
    

    Key: If you want it to be permanent open emacs .profile

    post the commands and press Ctrl-x Ctrl-c ( save-buffers-kill-terminal ).

提交回复
热议问题