Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the default Java path to other path in FreeBSD

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).

like image 577
Ratnesh Avatar asked Oct 12 '25 11:10

Ratnesh


1 Answers

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
like image 137
Konrad Rudolph Avatar answered Oct 14 '25 07:10

Konrad Rudolph