jenv: Jenv not setting JAVA_HOME
Did I miss something; i’m trying to reset my JAVA_HOME with jenv and have tried all the command and it seems it is updating the values but not the JAVA_HOME?
Any reason this should be happening?
Thanks,
Ian.
Ians-MacBook-Pro:~ ian$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
Ians-MacBook-Pro:~ ian$ jenv local oracle64-1.7.0.45
Ians-MacBook-Pro:~ ian$ jenv global oracle64-1.7.0.45
Ians-MacBook-Pro:~ ian$ jenv shell
shell shell-options
Ians-MacBook-Pro:~ ian$ jenv shell oracle64-1.7.0.45
Ians-MacBook-Pro:~ ian$ jenv version
oracle64-1.7.0.45 (set by JENV_VERSION environment variable)
Ians-MacBook-Pro:~ ian$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
Ians-MacBook-Pro:~ ian$ jenv versions
system
oracle64-1.6.0.65
* oracle64-1.7.0.45 (set by JENV_VERSION environment variable)
oracle64-1.8.0-ea
Ians-MacBook-Pro:~ ian$ echo $JENV_VERSION
oracle64-1.7.0.45
Ians-MacBook-Pro:~ ian$ cat .java-version
oracle64-1.7.0.45
Ians-MacBook-Pro:~ ian$ ```
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 89
Commits related to this issue
- #44 Create export plugin for zsh/bash that export JAVA_HOME on directory change — committed to jenv/jenv by gcuisinier 10 years ago
I solved setting JAVA_HOME by adding these lines to .zshrc after eval “$(jenv init -)”
I can use jenv_set_java_home alias to set JAVA_HOME after changing it with jenv .
You can set JAVA_HOME (and JDK_HOME) by enabling the export plugin
jenv enable-plugin export
Hello,
The JAVA_HOME is setup for command managed by jenv ( java, javac, … and if plugin activated for mvn, gradle, … ).
If you need external command to be aware of jenv’s java-version, you can try 👍
Sample :
I had same issue with maven and JAVA_HOME after upgrading my jenv using homebrew and finally found the solution for me. It seems like plugins need to be disabled and enabled to fix the issue.
I actually, opened up new terminal after disabling plugins and continued there. Hopefully, it helps someone else having same issue with me.
Can you try the new “export” plugin ?
jenv enable-plugin export
add the following line in
.zsh
or.bashrc
export JAVA_HOME="$(jenv prefix)
afterif which jenv > /dev/null; then eval "$(jenv init -)"; fi
I’m still confused… Why shouldn’t jenv set the JAVA_HOME globally when requested? there are 1000s of custom programs that rely on this parameter and it would be cool if you can change it with a single command line. FYI, I moved from jenv to simple bash script titled “java7” & “java8” that does just that, i.e. sets the JAVA_HOME & system path to the applicable JDK
On 2 April 2014 21:27, Lari Hotari notifications@github.com wrote:
It makes no sense to not set
JAVA_HOME
.jenv
is supposed to “Manage your Java environment” yet it does not set what’s arguably the most critical java environment variable.The idea that one must wrap their commands with
jenv exec
or use a plugin is invasive and impractical. Existing programs, scripts, cronjobs, service monitors, workflows that depend onJAVA_HOME
should not have to be tracked down and modified. Why write 10s of plugins in lieu of setting one variable?A great example: JRuby uses
JAVA_HOME
to find the underlying JVM. One should not have to typejenv exec ruby a_program.rb
.jenv
should be transparent.Any reason the export plugin isn’t enabled by default? When would you potentially want your
$JAVA_HOME
not to reflect the virtual environment you just setup and it this more common than wanting all your java settings to be on the same page when you do ajenv global x.y.z
?Intellij IDEA needs this too. It should be a given that you set JAVA_HOME.
Do you try this :
jenv enable-plugin grails jenv enable-plugin groovy
Spring Boot is not yet supported, indeed.
When i do
jenv enable-plugin export
I getGonna go delete jenv from my machine…
Nearly nothing suggested here for fish worked for me, nor in the readme, or in the scripts output. I added this to my .config/fish/config.fish
set -x JAVA_HOME (jenv prefix)
When running
jenv global x.y.z
(local
, neither) it doesn’t seem to automatically update JAVA_HOME in the current shell.Since no one mentioned it, and it was blocking me, per https://github.com/jenv/jenv/issues/78#issuecomment-94264183, if you have ~/.mavenrc present and pointing to a JDK, it will ignore what you do with
jenv
, even if you have everything else set up properly. Nothing from this thread was working for me, and then I commented out the line in that file setting JAVA_HOME and now everything is working great 👍@HaoH you forgot to put " at the end of the line
Thanks, it worked
What I did is a little bit of a hack, but I think that it would remove the need for all of the plugins.
Inside of the .jenv directory, I created a fake-java-home/bin with a symlink to the shims directory. Then in my bash, I pointed JAVA_HOME to the .jenv/fake-java-home directory. This means that any program trying to use java, will be redirected to the shim automatically.
Groovy and Maven and Gradle all react as expected (meaning they react to any local .java-version files)
You can try :
jenv enable-plugin export
ok, I found the bug. I expect the shell to be “bash”, “zsh” or "fish …
Here it’s “/usr/lcal/bin/shell” … and so that’s don’t work correctly.
To fix, modify you .bash_profiles from :
to
This would be much better. Especially since it seems quite tricky/error-prone to even get the plugin enabled, particularly in a scripted/unattended fashion that doesn’t rely on “restart your terminal to fix” (see https://github.com/jenv/jenv/issues/64).
To get maven to us the java version from jenv (maven uses JAVA_HOME):
echo 'JAVA_HOME=$(/usr/libexec/java_home -v $(jenv version-name))' >> ~/.mavenrc
source ~/.mavenrc
https://medium.com/@danielnenkov/multiple-jdk-versions-on-mac-os-x-with-jenv-5ea5522ddc9b
Ok… It seems that the maven plugin is not correctly loaded. Could you try again :
I’ve published a new version of jenv in homebrew. Could you upgrade and run 👍
jenv doctor
Thanks
Hmm ok it seems that it has nothing to do with the maven enforcer plugin jenv does not set the java version properly for maven. If I run maven with the
-X
it shows up that maven still runs with the system java environment:despite I enabled the maven plugin for jenv.
@gcuisinier No specific tool in mind- i’m more relating this to every day development - i may need to compile/execute 1 sourceset in JDK7 and another in JDK8 meaning that I need to change the JDK version frequently
On 3 April 2014 10:41, Gildas Cuisinier notifications@github.com wrote:
It’s not mandatory to user “jenv exec” to get the good version of Java. Jenv modify the path to use the good one (base one global, local or shell).
But in Java, some tools need to know where is the JDK. And the JAVA_HOME env variable is used for this. JAVA_HOME must point to the selected Java, not the global one. At this time, I export the JAVA_HOME in the jenv exec ( which is called by the java “wrapper” ).
So, if your command is a script that need to know where is the JAVA_HOME before calling java, you should call jenv exec yourScript
If your command used the “java” in the path, it’s not mandatory.