Setting the JAVA_HOME and PATH on MacOS

时光毁灭记忆、已成空白 提交于 2021-02-07 10:52:26

问题


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"

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

Thanks for your help


回答1:


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"

Check that it works correctly with:

java -version
ant -version

Then add the export lines to ~/.bash_profile or /etc/profile.




回答2:


  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

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/


来源:https://stackoverflow.com/questions/20822101/setting-the-java-home-and-path-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!