jEnv is a command line tool to set the JAVA_HOME enviornment variable. The blog of [Configuring jenv the right way)[https://developer.bring.com/blog/configuring-jenv-the-right-way/] gives the right way to set it – it fixed my sbt project too.
Setup
- Install jEnv:
brew install jenv - Set Zsh:
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrcecho 'eval "$(jenv init -)"' >> ~/.zshrc
- run
unset JAVA_TOOL_OPTIONS(imortant!) - User brew to install JDK versions from AdoptOpenJDK
- run
/usr/libexec/java_home -Vto see installed versions. They are installed in/Library/Java/JavaVirtualMachines - add each JDK to jenv, for example
jenv add /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home - use
jenv versionsto see all versions - run
jenv enable-plugin mavenandjenv enable-plugin export
Set Version and Verify
Use jenv global 11.0 to set global. Use jenv local 11.0 to set local.
To verify, run echo $JAVA_HOME and javac -version.