Golovaci Lena
Golovaci Lena

Reputation: 87

Should I set JAVA_HOME if java is already added to PATH?

Why some applications (like Ant) need JAVA_HOME variable if java is already added to PATH?

And following that thought, why, when installing Ant we must also add ANT_HOME variable, even if we already added Ant to PATH?

Why instead of this:

export ANT_HOME=/Library/apache-ant-1.9.4
export PATH=${PATH}:${ANT_HOME}/bin

Shouldn't we just use

export PATH=${PATH}:/Library/apache-ant-1.9.4/bin 

Are there more reasons other than readability?

Upvotes: 0

Views: 57

Answers (1)

yole
yole

Reputation: 97148

The PATH variable can contain multiple different versions of Java or Ant. The JAVA_HOME and ANT_HOME variables uniquely identify the version of Java or Ant used when starting from the command line.

Also, these environment variables are typically used in shell scripts that start the corresponding program, and it's much easier to deal with an environment variable that points to a single path, rather than a collection of paths.

Upvotes: 3

Related Questions