将默认的Java路径更改为FreeBSD中的其他路径

huangapple go评论82阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年9月4日 17:37:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63738605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定