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

查看:27
本文介绍了我应该在 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 首选项窗格中定义)的符号链接.

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

参考资料:

一篇文章在 Spring Tool Suite (Eclipse) 中配置 JDK2019) 在 MacOS 上

这篇关于我应该在 macOS X 10.6 上设置什么 JAVA_HOME 环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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