简体   繁体   English

mvn -version错误:我们无法执行/ usr / libexec / java_home / bin / java

[英]mvn -version error: We cannot execute /usr/libexec/java_home/bin/java

====== EDIT 2: ======编辑2:

I used the same code as mentioned below in edit 1, my error apparently was not in the code itself but rather due to source ~/.bash_profile not updating my file as expected. 我在编辑1中使用了与下面提到的相同的代码,我的错误显然不在代码本身,而是由于源〜/ .bash_profile未按预期更新我的文件。 I think, however (thank you @eckes) please see the maven bug:( BTW: jira.codehaus.org/browse/MNG-5686 – eckes 39 secs ago) 不过我想(谢谢你@eckes)请看maven bug :( BTW:jira.codehaus.org/browse/MNG-5686 - eckes 39秒前)

EDIT 1: this is not a duplicate of: What should I set JAVA_HOME to on OSX 编辑1:这不是重复: 我应该在OSX上设置JAVA_HOME

I have tried all of the solutions mentioned in the above post, and they do not work for me. 我已经尝试了上面提到的所有解决方案,但它们对我不起作用。 My issue is that I am doing one of the solutions listed there here (I tried the others). 我的问题是我正在做其中列出的解决方案之一(我尝试了其他解决方案)。 I am still getting the error. 我仍然得到错误。

I'm currently trying as per above instructions: 我正按照上述说明尝试:

  export JAVA_HOME=$(/usr/libexec/java_home)

and getting: 得到:

  source ~/.bash_profile
  mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/libexec/java_home/bin/java

======= I installed the latest java jdk from oracle =======我从oracle安装了最新的java jdk

java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

I installed Xcode to install maven however recent documentation states that I may use brew ( Maven Install on Mac OS X ) 我安装了Xcode来安装maven但是最近的文档声明我可以使用brew( Mac OS X上的Maven Install

I installed maven with: 我安装了maven:

//install brew
brew doctor
brew install maven

I then tried: 然后我尝试了:

mvn -version
     Error: JAVA_HOME is not defined correctly.

I found: http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac 我发现: http//hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac

However this is based on java 7 I believe. 不过这是基于java 7我相信的。 But it seemed likely to be a fix. 但它似乎可能是一个修复。

There is no bash_profile on the new mac ( https://apple.stackexchange.com/questions/26928/no-bash-profile-in-os-x-lion ) 新mac上没有bash_profile( https://apple.stackexchange.com/questions/26928/no-bash-profile-in-os-x-lion

So I created and edited my bash_profile with: 所以我创建并编辑了我的bash_profile:

touch ~/.bash_profile
vim ~/.bash_profile
//and added the line export JAVA_HOME=(/usr/libexec/java_home)

My problem is that even with this fix I am still getting the following error: 我的问题是即使使用此修复程序,我仍然会收到以下错误:

 mvn -version
      Error: JAVA_HOME is not defined correctly.
      We cannot execute /usr/libexec/java_home/bin/java

I checked however that within my file system java_home is where the file lies. 我检查了在我的文件系统中java_home是文件所在的位置。 There is no "/usr/libexec/java_home/bin/java" in my file system as maven error'ed out on. 我的文件系统中没有“/ usr / libexec / java_home / bin / java”作为maven错误。

Has anyone else encountered this with the new java 8, and brew installed maven? 有没有其他人遇到过这个新的java 8,并且brew安装了maven? I'm using a MacBook Pro (Retina, 13-inch, Mid 2014) running Yosemite. 我正在使用运行Yosemite的MacBook Pro(Retina,13英寸,2014年中)。 I've installed a setup like this before but never encountered this issue. 我以前安装过这样的设置,但从未遇到过这个问题。

**Note: **注意:

I found this: http://www.mkyong.com/java/maven-java_home-is-not-defined-correctly-on-mac-osx/ 我发现了这个: http//www.mkyong.com/java/maven-java_home-is-not-defined-correctly-on-mac-osx/

Which I thought would definitely be my fix. 我认为这肯定是我的修复。 Correct me if I'm wrong but I believe the difference is the parenthesis. 如果我错了,请纠正我,但我相信差异是括号。

Ex: 例如:

 export JAVA_HOME=/usr/libexec/java_home

vs VS

 export JAVA_HOME=(/usr/libexec/java_home)

However my error has not been fixed. 但是我的错误还没有解决。 (Also just in case anyone asks I source(ed) it before rerunning.) It did however change my error. (也是为了以防万一有人在重新运行之前要求我(它)来源。)但它确实改变了我的错误。 It removed the additional /bin/java. 它删除了额外的/ bin / java。

 mvn -version
      Error: JAVA_HOME is not defined correctly.
      We cannot execute /usr/libexec/java_home/bin/java

JAVA_HOME: JAVA_HOME:

 echo $JAVA_HOME
      /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

**note i tried the $() syntax and this did not fix the problem. **注意我尝试了$()语法,但这并没有解决问题。

You missed on one little thing, I believe: 你错过了一件小事,我相信:

export JAVA_HOME=$(/usr/libexec/java_home)
                 ⬆︎
          This dollar sign

This tells the shell "The value of this expression is the output from executing the following command ( /usr/libexec/java_home) )" 这告诉shell“此表达式的值是执行以下命令的输出( /usr/libexec/java_home) )”

Running the command gives the proper java home for the mac (if you have a single JDK installed), and that value is placed in JAVA_HOME. 运行该命令为mac提供了正确的java主目录(如果安装了单个JDK),并且该值放在JAVA_HOME中。 Without the dollar sign, it just puts the name of the command there. 没有美元符号,它只是将命令的名称放在那里。

I write on .bash_profile file these lines and then work for me. 我在.bash_profile文件上写下这些行,然后为我工作。

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/Users/(YOUR USER)/Documents/apache-maven-3.0.3/bin:$PATH
export PATH=$JAVA_HOME/jre/bin:$PATH

Note: work on macOS Sierra (10.12.6) 注意:在macOS Sierra上工作(10.12.6)

Follow this link : https://stackoverflow.com/a/44564303/5005676 If you see the mvn script: The code fails here --- 请访问此链接: https//stackoverflow.com/a/44564303/5005676如果您看到mvn脚本:代码在这里失败---

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) 步骤1:打开mvn脚本/Users/Username/apache-maven-3.0.5/bin/mvn(使用less命令打开,如:less /Users/Username/apache-maven-3.0.5/bin/mvn)

Step 2: Find out the below code in the script: 第2步:在脚本中找出以下代码:

  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. 第3步:发生这种情况是因为没有设置JAVACMD变量。 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 密钥:如果您希望它永久打开emacs .profile

post the commands and press Ctrl-x Ctrl-c ( save-buffers-kill-terminal ). 发布命令并按Ctrl-x Ctrl-c(save-buffers-kill-terminal)。

In my case, I had two entries for JAVA_HOME in my ~/.bash_profile and the last one was taking precedence. 就我而言,我在〜/ .bash_profile中有两个JAVA_HOME条目,最后一个条件优先。 I just deleted the one which was wrong and it worked. 我刚刚删除了一个错误的并且有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何解决错误:JAVA_HOME未正确定义。 我们不能执行/ usr / libexec / java_home / bin / java吗? - How do I fix Error: JAVA_HOME is not defined correctly. We cannot execute /usr/libexec/java_home/bin/java? /usr/libexec/java_home 返回错误时,如何在 MacOS Monterey 中设置 JAVA_HOME? - How to set JAVA_HOME in MacOS Monterey when /usr/libexec/java_home returns an error? PySpark:“/usr/libexec/java_home/bin/java:不是目录”(macOS Big Sur) - PySpark: "/usr/libexec/java_home/bin/java: Not a directory" (macOS Big Sur) /usr/libexec/java_home -v<version> 找到正确的 JDK 版本,但仅在第一次更新</version> - /usr/libexec/java_home -v <version> finds the right JDK version but updates it only the first time 为什么命令 /usr/libexec/java_home 不起作用? - Why command /usr/libexec/java_home doesn't work? 运行 /usr/libexec/java_home 给出无效目录? - Running /usr/libexec/java_home gives invalid directory? 如何将 /usr/libexec/java_home 指向自定义 jdk 安装? - How to point /usr/libexec/java_home to custom jdk installation? 使 export JAVA_HOME=`/usr/libexec/java_home -v 1.8` 永久化 - Make export JAVA_HOME=`/usr/libexec/java_home -v 1.8` permanent 在 MacOS 升级到 Big Sur 后,使用 /usr/libexec/java_home 切换 java 家庭停止工作 - Switch java home using /usr/libexec/java_home stop working after MacOS upgrade to Big Sur 错误:JAVA_HOME 定义不正确。 我们无法执行 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java - Error: JAVA_HOME is not defined correctly. We cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM