Jenv - same java version added multiple times
Asked Answered
J

4

11

I am using Jenv to manage multiple java version on My MacBook(OS X Yosemite).

jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
oracle64-1.6.0.65 added
1.6.0.65 added
1.6 added

and while adding Java 1.8

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
oracle64-1.8.0.60 added
1.8.0.60 added
1.8 added

and jenv version show multiple line of the same version infact it is one version?

jenv versions

    * system (set by /Users/$USERNAME/.jenv/version)
      1.6
      1.6.0.65
      1.8
      1.8.0.60
      oracle64-1.6.0.65
      oracle64-1.8.0.60
Jerrine answered 27/10, 2015 at 17:31 Comment(0)
S
3

You can always add/remove/change aliases in your ~/.jenv/versions folder. Those are just links.

Standee answered 15/8, 2022 at 12:51 Comment(2)
Thanks, I had a repository that wanted me to use 17 but jenv had only added symlinks for 17.0 and 17.0.4 so I was quickly able to add another one manually for 17.Rolanderolando
@Rolanderolando - this was a pretty long standing bug on macos and BSD which is fixed in the latest version. As an aside jenv has commands to remove aliases (jenv remove <alias>) and and your own (jenv add <alias> /path/to/java/home)Devoe
E
2

If you look inside the .jenv folder you can see all the three different instances of the same version.

Emetic answered 11/11, 2015 at 16:6 Comment(2)
yes but why? eg: for one version why it repeated say 1.6 , 1.6.065, oracle64-1.6.0.65Jerrine
1.6 is the major version and the others are the minor versions. If you have any bugs related to major version and want to use a specific fixed version you can switch to 1.6.0.XX or to use a version from a specific oracle version or any other.Emetic
S
1

I wrote a script to handle my JEnv environment.

# configure Java  http://www.jenv.be/
# install Java: brew cask install java, brew cask install java7
# set global default: setJavaGlobal 1.7, jenv global 1.7
# set local folder default: jenv local 1.8
# 
JENV_HOME=$HOME/.jenv
export PATH=.:$PATH:$JENV_HOME/bin
eval "$(jenv init -)"
#export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
alias jenv_set_java_home='export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"'
setJavaGlobal() { 
  jenv global $1;
  jenv_set_java_home
  echoJavaSetup
}
setJavaLocal() { 
  jenv local $1;
  jenv_set_java_home
  echoJavaSetup
}
echoJavaSetup() {
  echo --------------------
  echo NEW JAVA SETUP:
  echo "  PATH: $PATH"
  export JAVA_VERSION=`java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'`
  echo "  JAVA: $JAVA_VERSION, $JAVA_HOME"
  jenv versions
  echo --------------------
}
removeJavaLocal() {
  rm -rf ./.java-version
}
showJava() {
  echo --------------------
  echo EXISTING JAVA SETUP:
  echo "  PATH: $PATH"
  export JAVA_VERSION=`java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'`
  echo "  JAVA: $JAVA_VERSION, $JAVA_HOME"
  jenv versions
  if [ -f ./.java-version ]; then
    echo "Using Java LOCAL DEFAULT.  Not using global default!  Run command 'removeJavaLocal' to change to global default."
  fi
  echo --------------------
}
Snippet answered 28/4, 2016 at 22:11 Comment(0)
D
0

This is an intentional feature of jenv which allows you to work with multiple major versions of Java by allowing you to use versions depending on the specificity you require.

To see where all your aliases point you can run jenv versions --verbose.

In general you probably just want to specify the major version for a project/shell/globally (e.g. 1.8) but maybe in one project you need a specific version (e.g. 1.8.0.272) in which a JVM bug is fixed. Similarly you can have one project you want to build against openjdk 1.8 and another you want to build against corretto 1.8.

If you want to cleanup the more specific aliases you can use a command like below which would leave you with just 1.6 and 1.8

jenv remove 1.6.0.65 oracle64-1.6.0.65 1.8.0.60 oracle64-1.8.0.60

Devoe answered 23/3 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.