Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

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.

On OSX 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

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?

1 Answer

0 votes
by (46k points)

It's very easy you just need to set JAVA_HOME to the output of the command, which should provide you the Java path defined in your Java preferences. Here's a snippet from .bashrc file, which initiates this variable:

export JAVA_HOME=$(/usr/libexec/java_home)

I haven't experienced any problems with this technique.

Sometimes you need to alter the value of JAVA_HOME to an earlier version of Java. For instance, one program I'm having requires 32-bit Java 5 on OS X, so while using that program, I set JAVA_HOME by running:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)

For those of you who don't hold java_home in your path figure it like this.

sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 17, 2021 in Java by Harsh (1.5k points)
0 votes
1 answer
asked Jul 10, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Jul 10, 2019 in Java by Krishna (2.6k points)

Browse Categories

...