在 MacOS 上设置 JAVA_HOME 和 PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20822101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:36:19  来源:igfitidea点击:

Setting the JAVA_HOME and PATH on MacOS

javalinuxmacosapacheant

提问by Judy

I want to execute build.xml file using ant. But I am having trouble with recognizing the path for ant and Java. I tried changing the location to the correct location in bashrc as well as tried changing it for current command window using following commands:

我想使用 ant 执行 build.xml 文件。但是我无法识别 ant 和 Java 的路径。我尝试将位置更改为 bashrc 中的正确位置,并尝试使用以下命令为当前命令窗口更改它:

export path=/usr/local/apache-ant/bin:"$PATH"
echo 'export path=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bin:"$PATH"

similarly echo to profile for JAVA_HOME But when I check the paths for these they are not changed. Am I missing something?

与 JAVA_HOME 的配置文件类似,但是当我检查这些路径时,它们没有改变。我错过了什么吗?

echo $path
/usr/local/apache-ant/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin


echo $JAVA_HOME
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Thanks for your help

谢谢你的帮助

采纳答案by Elliott Frisch

It's PATHnot path, and your JAVA_HOMEis not under "Internet Plug-Ins" - try a find / -name "javac". Also, are you sure that you've installed Java? Finally, after you have set your JAVA_HOMEcorrectly do a

PATHpath,和你JAVA_HOME是不是在“互联网插件” -尝试find / -name "javac"。另外,你确定你已经安装了Java吗?最后,在您JAVA_HOME正确设置后,请执行以下操作

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"
export ANT_HOME="/usr/local/apache-ant"
export PATH="$PATH:$JAVA_HOME/bin:$ANT_HOME/bin"

Check that it works correctly with:

检查它是否正常工作:

java -version
ant -version

Then add the exportlines to ~/.bash_profileor /etc/profile.

然后将export行添加到~/.bash_profile/etc/profile

回答by Gautam

  1. echo $JAVA_HOME if returns empty(export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home)
  2. echo $PATH if returns empty(export PATH=$PATH:$JAVA_HOME/bin)
  3. export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.3
  4. export M2=$M2_HOME/bin
  5. mvn --version
  1. echo $JAVA_HOME 如果返回空(导出 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home)
  2. echo $PATH 如果返回空(export PATH=$PATH:$JAVA_HOME/bin)
  3. export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.3
  4. 出口 M2=$M2_HOME/bin
  5. mvn --version

ALL SET *******

搞定 *******

In case if this doesn't work after this step,

如果在这一步之后这不起作用,

  1. vi .profile
  2. export PATH={$PATH}:'/usr/local/apache-maven/apache-maven-3.2.3/bin/
  1. vi .profile
  2. 导出路径={$PATH}:'/usr/local/apache-maven/apache-maven-3.2.3/bin/