1

I have oracle and adoptOpen's JDK installed.

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    11.0.5, x86_64: "Java SE 11.0.5"    /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home
    11.0.4, x86_64: "AdoptOpenJDK 11"   /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    1.8.0_161, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

In the past, i switched between jdk11 and jdk1.8 by using:

alias jdk11='export JAVA_HOME=`/usr/libexec/java_home -v11`'
alias jdk8='export JAVA_HOME=`/usr/libexec/java_home -v1.8`'

but I can't see how to select between the two jdk11 providers. java_home -v11 will always get me the Oracle path and the help/manpage do not show any option that I could use to differentiate them.

How can I tell java_home that I want "AdoptOpenJDK 11" and not "Java SE 11"?

Gabriel
  • 177
  • 13

2 Answers2

1

enter image description here

Computer > Properties > Advanced System Settings > Environment Variables

Alan Deep
  • 2,037
  • 1
  • 14
  • 22
  • thanks for the answer with pics and all. but sorry if it wasn't clear, not looking how to set the env var, but how to get the right value when you have several JDK available. – Gabriel Oct 25 '19 at 20:22
1

java_home does not seem to have a way to filter by provider / vendor. I was able to filter the output of java_home -V to get what you want.

For your particular example,

alias jdk11='export JAVA_HOME=`/usr/libexec/java_home -V 2>&1 > /dev/null | grep "OpenJDK 11" | sed -e "|.*/Library|/Library|"`'
dorab
  • 807
  • 5
  • 13