本文共 2769 字,大约阅读时间需要 9 分钟。
本文翻译自:
Many Java applications that use shell scripts to configure their environment use the JAVA_HOME
environment variable to start the correct version of Java, locate JRE JARs, and so on. 许多使用shell脚本配置其环境的Java应用程序使用JAVA_HOME
环境变量来启动正确版本的Java,找到JRE JAR等。
On OSX 10.6, the following paths seem to be valid for this variable 在OSX 10.6上,以下路径似乎对此变量有效
/Library/Java/Home/System/Library/Frameworks/JavaVM.framework/Home/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane). 其中一些是实际当前VM的符号链接(如“Java首选项”窗格中所定义)。
But which one should be used—or is it okay to use any of them? 但应该使用哪一个 - 或者可以使用其中任何一个?
参考:
I tend to use /Library/Java/Home
. 我倾向于使用/Library/Java/Home
。 The way the preferences pane works this should be up to date with your preferred version. 首选项窗格的工作方式应与您的首选版本保持同步。
Does Snow Leopard still have /usr/libexec/java_home
? Snow Leopard还有/usr/libexec/java_home
吗? On 10.5, I just set JAVA_HOME
to the output of that command, which should give you the Java path specified in your Java preferences. 在10.5上,我只是将JAVA_HOME
设置为该命令的输出,该命令应该为您提供Java首选项中指定的Java路径。 Here's a snippet from my .bashrc
file, which sets this variable: 这是我的.bashrc
文件的片段,它设置了这个变量:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique. 我没有遇到过这种技术的任何问题。
Occasionally I do have to change the value of JAVA_HOME
to an earlier version of Java. 有时我必须将JAVA_HOME
的值更改为早期版本的Java。 For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME
by running: 例如,我正在维护的一个程序在OS X上需要32位Java 5,因此在使用该程序时,我通过运行来设置JAVA_HOME
:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home
in your path add it like this. 对于那些在您的路径中没有java_home
,请像这样添加它。
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
现在Java似乎安装在/Library/Java/JavaVirtualMachines
Also, it`s interesting to set your PATH to reflect the JDK. 另外,设置PATH以反映JDK很有意思。 After adding JAVA_HOME (which can be done with the example cited by 'mipadi'): 添加JAVA_HOME后(可以使用'mipadi'引用的示例完成):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile: 在〜/ .profile中添加:
export PATH=${JAVA_HOME}/bin:$PATH
PS: For OSX, I generally use .profile in the HOME dir instead of .bashrc PS:对于OSX,我通常在HOME目录中使用.profile而不是.bashrc
I'm on Mac OS 10.6.8 我在Mac OS 10.6.8上
The easiest solution works for me is simply put in 对我来说最简单的解决方案就是放入
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in 为了测试它是否有效,请加入
$ echo $JAVA_HOME
it shows 表明
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test 你也可以测试一下
$ which java
转载地址:http://vfexb.baihongyu.com/