英文:
Change the default Java path to other path in FreeBSD
问题
我有一个脚本从这个命令中获取Java路径:readlink -f $(which java)
。
但是它显示的是错误路径:/usr/local/bin/javavm
而我需要的是这个路径:/usr/local/openjdk8/bin/java
我尝试过执行导出命令:export JAVA_HOME=/usr/local/openjdk8/,但问题仍然存在。
我也尝试过这个帖子:https://stackoverflow.com/a/39691105/10220825
以及这个帖子:https://askubuntu.com/a/554052/905016
我还尝试过:sudo ln -s /usr/local/bin/javavm /usr/local/openjdk8/bin/java,但结果是ln: /usr/local/openjdk8/bin/java: File exists
,问题仍然存在。
我不想将其硬编码,也不想使用其他命令,比如which java
或者echo $JAVA_HOME
,因为脚本在Linux中得到了预期的结果,但在FreeBSD机器上出现了问题。
我也不想从readlink -f $(which java)
的输出中应用任何解析,比如awk
或者sed
。
有人能建议我如何更改readlink -f $(which java)
的值。
英文:
I have script to get the java path from this command: readlink -f $(which java)
.
But it displays wrong path : /usr/local/bin/javavm
While I need to have this path : /usr/local/openjdk8/bin/java
I tried to give export command: export JAVA_HOME=/usr/local/openjdk8/, but the issue remains same.
I tried this post as well : https://stackoverflow.com/a/39691105/10220825
and this post : https://askubuntu.com/a/554052/905016
I also tried : sudo ln -s /usr/local/bin/javavm /usr/local/openjdk8/bin/java
but it results, ln: /usr/local/openjdk8/bin/java: File exists
and issue remain same.
I dont want to hardcode it, neither I want to use other command like which java
or echo $JAVA_HOME
as the script is getting the expected result in Linux but only problems with FreeBSD machine.
I also dont want to apply any parsing like awk
or sed
from the output of readlink -f $(which java)
.
Can someone suggest me how to change the value from readlink -f $(which java)
.
答案1
得分: 4
你所看到的是在FreeBSD上记录的行为。
如果你想选择特定的Java版本,请设置JAVA_VERSION
环境变量,例如:
JAVA_VERSION=8+ javac MyClass.java
如果你想找出正在运行的版本,设置JAVAVM_DRYRUN=yes
:
JAVAVM_DRYRUN=yes java
JAVAVM_DRYRUN=yes JAVA_VERSION=11 java
英文:
What you’re seeing is the documented behaviour on FreeBSD.
If you want to select a specific Java version, set the JAVA_VERSION
environment variable, e.g.:
JAVA_VERSION=8+ javac MyClass.java
If you want to find out what version is being run, set JAVAVM_DRYRUN=yes
:
JAVAVM_DRYRUN=yes java
JAVAVM_DRYRUN=yes JAVA_VERSION=11 java
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论