Skip to content

Instantly share code, notes, and snippets.

@stefanhendriks
Last active September 4, 2016 22:48
Show Gist options
  • Save stefanhendriks/56c51df1cf06def3679d to your computer and use it in GitHub Desktop.
Save stefanhendriks/56c51df1cf06def3679d to your computer and use it in GitHub Desktop.
Maven and JAVA_HOME

When running maven you might see a different JAVA_HOME version than when you're running java -version

In general sense this means when you run mvn a new shell is opened and your JAVA_HOME is (re)set. This means, especially if you need to work with different Java versions, that you must be sure you don't override the version you're working on.

First thing you need to make sure is that you only set JAVA_HOME once.

In relation to Maven you might have something set in :

  • ~/.mavenrc
  • /etc/mavenrc

Since these are Maven specific, I'd suggest to not make them (re)set the JAVA_HOME.

Multiple Java Versions

I use Jenv for this.

When using Jenv, you can now set a JAVA_HOME like this in your .bashrc or .zshrc etc:

export JAVA_HOME=$(/usr/libexec/java_home -v $(jenv version-name))

(inspired by this)

This line should be after the default initialization of Jenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment