在 MacOS 上设置 JAVA_HOME 和 PATH [英] Setting the JAVA_HOME and PATH on MacOS
问题描述
我想使用 ant 执行 build.xml 文件.但是我无法识别 ant 和 Java 的路径.我尝试将位置更改为 bashrc 中的正确位置,并尝试使用以下命令将其更改为当前命令窗口:
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:
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"
同样回显到 JAVA_HOME 的配置文件但是当我检查这些路径时,它们并没有改变.我错过了什么吗?
similarly echo to profile for JAVA_HOME But when I check the paths for these they are not changed. Am I missing something?
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
感谢您的帮助
推荐答案
It's PATH
not path
, and your JAVA_HOME
is not under "Internet 插件" - 尝试 find/-name "javac"
.另外,你确定你已经安装了Java吗?最后,在您正确设置 JAVA_HOME
后执行
It's PATH
not path
, and your JAVA_HOME
is 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_HOME
correctly do a
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"
检查它是否正常工作:
java -version
ant -version
然后将 export
行添加到 ~/.bash_profile
或 /etc/profile
.
Then add the export
lines to ~/.bash_profile
or /etc/profile
.
这篇关于在 MacOS 上设置 JAVA_HOME 和 PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!