gpt4 book ai didi

java - 如何知道环境变量是否设置成功(Mac)

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:01 24 4
gpt4 key购买 nike

尝试将 JAVA_HOME 环境变量设置为 JDK 的位置。ls -l 'which java' 返回 lrwxr-xr-x 1 root wheel 74 Nov 9 13:31/usr/bin/java ->/System/.../java

所以我假设 /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java 是我的 JDK 的正确位置。所以我应该做的就是编写 export JAVA_HOME=$(/System/.../java)

这样做后,我得到了大量的输出:

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.


-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

这看起来像是有关 java 命令使用的某种帮助。我的导出是否成功? JAVA_HOME 现在是否设置为我的 JDK 的位置?

最佳答案

首先,要使其永久生效,您必须在 Mac 中编辑 ~/.bash_profile 文件。在该文件中,键入上面输入的导出命令。

要检查它是否成功,请在终端中输入 echo $JAVA_HOME 并查看输出。这将告诉您 $JAVA_HOME 当前环境变量的设置。

此外,which 命令仅查找 java 的可执行文件,而不是 SDK 的存储位置。您需要找到您计算机上安装 java 的位置。对我来说,我的是这样的:

导出 JAVA_HOME=$(/usr/libexec/java_home)

当安装新版本的 java 时,这将自动更新。

关于java - 如何知道环境变量是否设置成功(Mac),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36745502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com