我应该在macOS X 10.6上设置JAVA_HOME环境变量吗? [英] What should I set JAVA_HOME environment variable on macOS X 10.6?

查看:61
本文介绍了我应该在macOS X 10.6上设置JAVA_HOME环境变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多使用shell脚本配置环境的Java应用程序都使用JAVA_HOME环境变量来启动正确版本的Java,定位JRE JAR等.

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.

在macOS X 10.6中,以下路径似乎对此变量有效

In macOS X 10.6, the following paths seem to be valid for this variable

/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current

其中一些是到实际当前VM的符号链接(如Java Preference窗格中所定义).

Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).

但是应该使用哪一个?或者可以使用其中任何一个?

But which one should be used—or is it okay to use any of them?

推荐答案

我只是将JAVA_HOME设置为该命令的输出,这将为您提供Java首选项中指定的Java路径.这是我的.bashrc文件中的代码片段,它设置了此变量:

I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:

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

该技术我没有遇到任何问题.

I haven't experienced any problems with that technique.

有时我确实必须将JAVA_HOME的值更改为Java的早期版本.例如,我要维护的一个程序在OS X上需要32位Java 5,因此在使用该程序时,我可以通过运行以下命令来设置JAVA_HOME:

Occasionally I do have to change the value of JAVA_HOME to an earlier version of 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:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)

对于您的路径中没有java_home的那些人,请像这样添加它.

For those of you who don't have java_home in your path add it like this.

sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home

参考:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆