-
Notifications
You must be signed in to change notification settings - Fork 385
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
Jenv not setting JAVA_HOME #44
Comments
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'm currious aswell... when using pyenv (a clone from rbenv for python) and pip (python package manager), I don't have to write pyenv exec pip in order to use the command. Is there a technical reason that doesn't manage the JAVA_HOME automatically when setting the global java version? |
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. 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. |
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 . |
Can you explain me why do you need JAVA_HOME to be set ? For which tools ? |
Groovy and Grails , they both contain special logic for setting JAVA_HOME on MacOSX . MacOSX (I'm running 10.9.3) also seems to set JAVA_HOME to the version controlled by MacOSX specific /usr/libexec/java_home . That's why I want to set JAVA_HOME to the global jenv java version in zshrc. |
Spring Boot has also similar logic , see https://github.com/spring-projects/spring-boot/blob/master/spring-boot-cli/src/main/executablecontent/bin/spring#L23 |
Do you try this : jenv enable-plugin grails Spring Boot is not yet supported, indeed. |
Thanks, that solves my use case for G&G . I guess we need a plugin for Spring Boot . 👍 |
I agree for the Spring boot plugin :-)
|
Thanks for the Spring Boot support. btw. It looks like gvm is setting my JAVA_HOME now. https://github.com/gvmtool/gvm/blob/master/src/main/bash/gvm-init.sh#L128 (I'd like to see gvm rely on jenv instead. btw. It would be cool if jenv could be installed/updated with gvm.) |
I'm still confused.. Why shouldn't jenv set the JAVA_HOME globally when On 2 April 2014 21:27, Lari Hotari notifications@github.com wrote:
|
I think a shell function could even detect that you have changed the working directory and update JAVA_HOME environment if it has to be changed. If that's the reason to do all of this plugin/rehashing/shingle business... |
@gcuisinier No specific tool in mind- i'm more relating this to every day On 3 April 2014 10:41, Gildas Cuisinier notifications@github.com wrote:
|
Yes, I do this everyday too .. The only part you don't have directly is shell script using JAVA_HOME explicitly. |
Intellij IDEA needs this too. It should be a given that you set JAVA_HOME. |
Hmm that odd I enabled the maven plugin but if I try to run jhipster with the spring-boot plugin the maven enforcer plugin seems not be aware of the java version set jenv, not before I run |
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
despite I enabled the maven plugin for jenv. |
To be sure, it's not a problem with Spring Boot, but with Mvn ? mvn -version show the system JDK ? could you provide me the output of : jenv version |
Hi it seems to be a general maven problem, sorry for the irritation in the first post. Yes the output in my previous post is from jenv version: jenv versions:
echo $PATH:
|
I've published a new version of jenv in homebrew. Could you upgrade and run 👍 jenv doctor Thanks |
Hi, I upgraded jenv with homebrew and run jenv doctor. At the first run I got this output:
So after re-adding the java versions, I run mvn -version in a project, where the jdk8 is set by jenv but it still uses the system jdk6. |
Could you provide me the output of command - v java |
Here is the output of command -v java: |
Ok now it gets even stranger. I remember that it has worked once with jenv and maven, so I removed the homebrew version of jenv and reinstalled it as shown here https://github.com/gcuisinier/jenv#gettings-started (without homebrew) and everything works fine. Now maven is aware of the changed java version via jenv. |
It makes no sense to not set
The idea that one must wrap their commands with A great example: JRuby uses
|
I agree, but jenv is made on the base of rbenv. rbenv use the "wrapping-way" to run the selected binaries. I am not a ruby user, but I think they don't have an equivalent en JAVA_HOME. In java, a lot of tools need JAVA_HOME variable. The plugin solution was the one I found to export this variable. It's not perfect, but without this, jenv should have been completely rewritten. For me, the main reason I made jenv was because I had several projects in Java 1.6, somes in Java 1.6, and other in 1.7. All based on maven. And jenv matched my needs completely. I know it's not perfect ! |
The way Java loads its libs is quite different than the way Ruby does. Solving the problem for Ruby isn't going to solve the problem for Java and vise versa -hence this issue.
Yes, there is no Doesn't setting Any contribution I would make would set |
Also I would mention that you do not set |
$ echo $PATH |
Mmm .. there is a bug somewhere. `ls /Users/CHI\dparupud/.jenv/shims`` I presume that mvn wrapper shim is not correctly created |
@gcuisinier, thanks for all your help. Now my ~ ( home) points to however I don't find .jenv folder in my home directory now. I did a brew uninstall and install again still with no luck. I think this is not an issue anymore but a problem specific to mine. I apologize for the confusion. What is the best way to uninstall jenv completely ? Apologies again. |
I think my problem is solved. Thanks for all your help dparupudi-mac:~ dparupud$ jenv global oracle64-1.8.0.31 |
First of all: gcuisinier, you did a great job! But unfortunately i also have a problem. I am using Fish and Jenv (first tried via brew, then installed manually) and have the following outputs:
`↪ cat ~/.config/fish/config.fish Mo 30 Mär 2015 19:21:02 CEST set fish_path $HOME/.oh-my-fish set fish_theme jacaetevha set fish_plugins theme . $fish_path/oh-my-fish.fish set fish_plugins git-flow set PATH $HOME/.jenv/bin $PATH jenv rehash 2>/dev/null set JENV_LOADED 1 and last:
What am i missing? (it's the same with or without oh-my-fish) |
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. bakerj1-mbpdu:.jenv bakerj$ ls -al total 32 drwxr-xr-x 21 bakerj OCLC\Domain Users 714 Apr 13 14:12 . drwxr-xr-x+ 56 bakerj OCLC\Domain Users 1904 Apr 13 14:44 .. drwxr-xr-x 13 bakerj OCLC\Domain Users 442 Apr 9 16:15 .git -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 1.7.0.45.time -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 1.7.time -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 1.8.0.05.time -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 1.8.time -rw-r--r-- 1 bakerj OCLC\Domain Users 1060 Apr 9 16:15 LICENSE -rw-r--r-- 1 bakerj OCLC\Domain Users 6385 Apr 9 16:15 README.md drwxr-xr-x 13 bakerj OCLC\Domain Users 442 Apr 9 16:15 available-plugins drwxr-xr-x 3 bakerj OCLC\Domain Users 102 Apr 9 16:15 bin drwxr-xr-x 4 bakerj OCLC\Domain Users 136 Apr 9 16:15 completions drwxr-xr-x 3 bakerj OCLC\Domain Users 102 Apr 13 14:13 fake-java-home drwxr-xr-x 4 bakerj OCLC\Domain Users 136 Apr 9 16:15 fish drwxr-xr-x 44 bakerj OCLC\Domain Users 1496 Apr 9 16:15 libexec -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 oracle64-1.7.0.45.time -rw-r--r-- 1 bakerj OCLC\Domain Users 0 Apr 9 16:20 oracle64-1.8.0.05.time drwxr-xr-x 4 bakerj OCLC\Domain Users 136 Apr 13 14:42 plugins drwxr-xr-x 51 bakerj OCLC\Domain Users 1734 Apr 13 14:44 shims -rw-r--r-- 1 bakerj OCLC\Domain Users 18 Apr 9 16:20 version drwxr-xr-x 8 bakerj OCLC\Domain Users 272 Apr 9 16:20 versions bakerj1-mbpdu:.jenv bakerj$ pwd /Users/bakerj/.jenv bakerj1-mbpdu:.jenv bakerj$ echo $JAVA_HOME /Users/bakerj/.jenv/fake-java-home bakerj1-mbpdu:.jenv bakerj$ bakerj1-mbpdu:.jenv bakerj$ ls $JAVA_HOME/bin appletviewer jar javadoc jcmd jhat jmc jstack keytool policytool schemagen unpack200 apt jarsigner javafxpackager jconsole jinfo jps jstat native2ascii rmic serialver wsgen extcheck java javah jdb jjs jrunscript jstatd orbd rmid servertool wsimport idlj javac javap jdeps jmap jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc bakerj1-mbpdu:.jenv bakerj$ Groovy and Maven and Gradle all react as expected (meaning they react to any local .java-version files) |
+1 Same behavior on my machine, with multiple command line applications and with IntelliJ. |
Hello there, have not read all comments about how to handle $JAVA_HOME... But I followed @solidjb example and it worked like a charm. |
Although most things seem to work fine, there's one small part where the export plugin fails and that's on the level of Mac OS X system environment variables. This is a problem, because IntelliJ IDEA looks at those for the value of JAVA_HOME for Maven. |
sdkman needs JAVA_HOME.. but jenv doesnt set it.. |
You can set JAVA_HOME (and JDK_HOME) by enabling the export plugin
|
@gcuisinier that totally did the job |
When i do
Gonna go delete jenv from my machine.... |
what version of jenv do you have ? |
same here - version is jenv 0.4.4 |
Maven 3.5 was picking up 9-ea irrespective of the jenv config. |
add the following line in |
Any reason the export plugin isn't enabled by default? When would you potentially want your |
@HaoH you forgot to put " at the end of the line
Thanks, it worked |
When running |
Since no one mentioned it, and it was blocking me, per #78 (comment), if you have ~/.mavenrc present and pointing to a JDK, it will ignore what you do with |
So these above seem to work but when I run My
My path:
Any thoughts? |
To get maven to us the java version from jenv (maven uses JAVA_HOME):
https://medium.com/@danielnenkov/multiple-jdk-versions-on-mac-os-x-with-jenv-5ea5522ddc9b |
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 |
I had same issue with maven and JAVA_HOME after upgrading my jenv using homebrew and finally found the solution for me.
I actually, opened up new terminal after disabling plugins and continued there. |
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 #64). |
Thanks @gcuisinier for this advice, I had a similar problem with a React Native app. Since React Native uses gradle, it seems the following solved the issue: jenv enable-plugin gradle |
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.
The text was updated successfully, but these errors were encountered: