博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我应该如何在OSX上设置JAVA_HOME
阅读量:2379 次
发布时间:2019-05-10

本文共 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? 但应该使用哪一个 - 或者可以使用其中任何一个?


#1楼

参考:


#2楼

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. 首选项窗格的工作方式应与您的首选版本保持同步。


#3楼

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

#4楼

现在Java似乎安装在/Library/Java/JavaVirtualMachines


#5楼

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


#6楼

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/

你可能感兴趣的文章
Linux内核中C编程生僻用法(GNU C)
查看>>
辞职后五险一金怎么处理?
查看>>
几种开源的TCP/IP协议栈对比
查看>>
C语言之断言
查看>>
程序员技术练级攻略
查看>>
#define
查看>>
C语言之if...else PK switch...case
查看>>
关于SVN方面的问题
查看>>
深入理解C语言
查看>>
编程成就:开发人员如何升级
查看>>
如何防止代码腐烂
查看>>
va_start va_end 的使用和原理
查看>>
Linux 中的零拷贝技术,第 2 部分
查看>>
零拷贝技术的研究与实现
查看>>
零拷贝与 sendfile
查看>>
directfb显示中文
查看>>
关于SIGPIPE导致的程序退出
查看>>
setsockopt()函数用法
查看>>
TCP之send函数研究
查看>>
Linux下访问内存物理地址
查看>>