Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #422 prevent export hook setting JAVA_HOME when system #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewflbarnes
Copy link
Contributor

@andrewflbarnes andrewflbarnes commented Mar 16, 2024

Fixes #369, fixes #422, fixes #295 and some formatting - follow up to #350

Mac

Available JVMs

$ ls /Library/Java/JavaVirtualMachines/; /usr/libexec/java_home 
jdk1.8.0_191.jdk        openjdk-11.jdk          openjdk-8.jdk           openjdk.jdk
/usr/local/Cellar/openjdk/21.0.2/libexec/openjdk.jdk/Contents/Home

Global/defaullt system

$ jenv version; jenv info java; jenv which java; echo $JAVA_HOME; jenv javahome; java -version
system (set by /Users/andrew.barnes/.jenv-test/version)
Jenv will exec : /usr/bin/java  
Exported variables :
  JAVA_HOME=/usr/local/Cellar/openjdk/21.0.2/libexec/openjdk.jdk
/usr/bin/java
/usr/local/Cellar/openjdk/21.0.2/libexec/openjdk.jdk
/usr/local/Cellar/openjdk/21.0.2/libexec/openjdk.jdk
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)

Shell 1.8

$ jenv version; jenv info java; jenv which java; echo $JAVA_HOME; jenv javahome; java -version
1.8 (set by JENV_VERSION environment variable)
Jenv will exec : /Users/andrew.barnes/.jenv-test/versions/1.8/bin/java  
Exported variables :
  JAVA_HOME=/Users/andrew.barnes/.jenv-test/versions/1.8
/Users/andrew.barnes/.jenv-test/versions/1.8/bin/java
/Users/andrew.barnes/.jenv-test/versions/1.8
/Users/andrew.barnes/.jenv-test/versions/1.8
openjdk version "1.8.0_402"
OpenJDK Runtime Environment (build 1.8.0_402-bre_2024_03_05_05_38-b00)
OpenJDK 64-Bit Server VM (build 25.402-b00, mixed mode)

Ubuntu

Note: run in docker with export JENV_ROOT=/.jenv

Available JVMs

# ls /usr/lib/jvm; update-alternatives --display java
java-1.21.0-openjdk-amd64  java-21-openjdk-amd64  openjdk-21
java - auto mode
  link best version is /usr/lib/jvm/java-21-openjdk-amd64/bin/java
  link currently points to /usr/lib/jvm/java-21-openjdk-amd64/bin/java
  link java is /usr/bin/java
  slave java.1.gz is /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-21-openjdk-amd64/bin/java - priority 2111
  slave java.1.gz: /usr/lib/jvm/java-21-openjdk-amd64/man/man1/java.1.gz

Global/default system

# jenv version; jenv info java; jenv which java; echo $JAVA_HOME; jenv javahome; java -version
system (set by /.jenv/version)
Jenv will exec : /usr/bin/java  
Exported variables :
  JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
/usr/bin/java
/usr/lib/jvm/java-21-openjdk-amd64
/usr/lib/jvm/java-21-openjdk-amd64
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-122.04.1, mixed mode, sharing)

Shell 21

# jenv version; jenv info java; jenv which java; echo $JAVA_HOME; jenv javahome; java -version
21 (set by JENV_VERSION environment variable)
Jenv will exec : /.jenv/versions/21/bin/java  
Exported variables :
  JAVA_HOME=/.jenv/versions/21
/.jenv/versions/21/bin/java
/.jenv/versions/21
/.jenv/versions/21
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-122.04.1, mixed mode, sharing)

Use java from the path with jenv shims and locations removed.
Set JAVA_HOME to be the linked java home from above, if it exists,
otherwise search for OS utility programs which can pinpoint the javahome
like libexec java_home or alternatives.
Fallback to whatever JAVA_HOME is currently set to if it can't otherwise
be resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant