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
JAVA_HOME not exported properly #188
Comments
Do you have enabled the export plugin?
|
I have the same problem.
|
I found issue. |
This is definitely not working correctly.
So clearly not doing what it is supposed to and jenv doctor is lying about it as well. Latest jenv installed via home brew. I have this in my .bash_profile:
The reason this project has a lot of issues related to JAVA_HOME being reported is that this variable is key to pretty much any custom shell script to launch e.g. maven, gradle, tomcat, jboss, etc. The expected behavior here is that jenv always manages JAVA_HOME. IMHO the plugin should not be needed. Any time you have jenv pointing to one thing and JAVA_HOME to another is a problem that is going to surprise/confuse users. So why not fix this properly? I know there are work arounds but they sort of defeat the point of having jenv. Is there any good technical reason for not setting this variable always? |
@jillesvangurp Most likely cause is that you had jenv set to 1.8 when the shell was started which set the JAVA_HOME var. But subsequently you changed the jenv version to 10 but you didn't restart the shell. Since shell wasn't restarted the JAVA_HOME remains initialized to the old 1.8 while jenv itself reports its current value 10 (extracted from the global/local .version files). From what I can deduce and the brief mention in the README docs: JAVA_HOME is set by the 'export' plugin at shell startup only. So behaviour is as designed and not a bug per say though I can't fathom why it's designed that way.
Hope that helps. |
This might help someone. While changing versions on the fly with In .{bash,zsh,local,whatever}rc file:
|
Thank @epferrari for your feedback. We will check how to export directly the JAVA_HOME directly on jenv local|global call. |
Also having this issue while using jenv shell inside a script (0.5.0) |
I'm new to jenv and ran into this problem.
Exactly. After installing jenv, I thought JAVA_HOME would always be either whatever is set in your shell profile, or whatever jenv would automatically set it to, based on I don't understand why an "export plugin" needs to be enabled separately. How does jenv work at all, if not by exporting JAVA_HOME? |
This appear to have done the trick for me #188 (comment) |
There is still a problem with fish shell. bass 'eval "$(jenv init -)"; eval "$(jenv enable-plugin export)"' note that the command must be inline. split into two lines and it wont work. |
Same thing for me:
|
I had problems with the After a little bit of tracing, I noticed that Therefore, the following initialization sequence under bash now works better for me:
|
I found the problem with fish shell is that the jenv export plugin only provides hooks for bash and zsh. Fish hook is not implemented at all. I have hardcoded the following script in config.fish to enable export hook in fish. # load jenv and enable export hook
status --is-interactive; and source (jenv init - | psub)
function __jenv_export_hook --on-event fish_prompt
set -gx JAVA_HOME (jenv javahome)
set -gx JENV_FORCEJAVAHOME true
if test -e "$JAVA_HOME/bin/javac"
set -gx JDK_HOME "$JAVA_HOME"
set -gx JENV_FORCEJDKHOME true
end
end |
Ensures that JAVA_HOME is set properly and that prompts get correct info on current java version. From jenv#188 (comment) Fixes jenv#188
Ensures that JAVA_HOME is set properly and that prompts get correct info on current java version. From jenv#188 (comment) Fixes jenv#188
Trying to switch over from bash -> zsh. When I run: Any ideas here? Thanks! |
@unhuman try |
After installing, and adding jdk's 8 and 9, then setting jenv global to 1.8, I get expected results when issuing
jenv info java
.java -version
also outputs expected results. However, other tools that rely on JAVA_HOME are failing, and incorrectly referencing the wrong java version's home. I don't have any other variable exports anywhere.echo $JAVA_HOME
returns a blank line.The text was updated successfully, but these errors were encountered: