Skip to content
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

Closed
kellizer opened this issue Feb 27, 2014 · 89 comments
Closed

Jenv not setting JAVA_HOME #44

kellizer opened this issue Feb 27, 2014 · 89 comments

Comments

@kellizer
Copy link

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$ ```
@gcuisinier
Copy link
Collaborator

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 👍

jenv exec /your/command/here

Sample :

hikage at iKage in ~
$ echo $JAVA_HOME


hikage at iKage in ~
$ jenv exec bash
bash-3.2$ echo $JAVA_HOME
/Users/hikage/.jenv/versions/oracle64-1.8.0-ea
bash-3.2$ exit
exit

hikage at iKage in ~
$ 

@duydao
Copy link

duydao commented Mar 25, 2014

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?

@gcuisinier
Copy link
Collaborator

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.

@lhotari
Copy link

lhotari commented Apr 2, 2014

I solved setting JAVA_HOME by adding these lines to .zshrc after eval "$(jenv init -)"

export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
alias jenv_set_java_home='export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"'

I can use jenv_set_java_home alias to set JAVA_HOME after changing it with jenv .

@gcuisinier
Copy link
Collaborator

Can you explain me why do you need JAVA_HOME to be set ? For which tools ?

@lhotari
Copy link

lhotari commented Apr 2, 2014

Groovy and Grails , they both contain special logic for setting JAVA_HOME on MacOSX .
see https://github.com/groovy/groovy-core/blob/master/src/bin/startGroovy#L70 and https://github.com/grails/grails-core/blob/master/grails-resources/src/grails/home/bash/startGrails#L58 .

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.

@lhotari
Copy link

lhotari commented Apr 2, 2014

@gcuisinier
Copy link
Collaborator

Do you try this :

jenv enable-plugin grails
jenv enable-plugin groovy

Spring Boot is not yet supported, indeed.

@lhotari
Copy link

lhotari commented Apr 2, 2014

Thanks, that solves my use case for G&G . I guess we need a plugin for Spring Boot . 👍

@gcuisinier
Copy link
Collaborator

I agree for the Spring boot plugin :-)
Le 2 avr. 2014 19:33, "Lari Hotari" notifications@github.com a écrit :

Thanks, that solves my use case for G&G . I guess we need a plugin for
Spring Boot . [image: 👍]

Reply to this email directly or view it on GitHubhttps://github.com//issues/44#issuecomment-39359521
.

@lhotari
Copy link

lhotari commented Apr 2, 2014

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.)

@kellizer
Copy link
Author

kellizer commented Apr 3, 2014

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:

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.)

Reply to this email directly or view it on GitHubhttps://github.com//issues/44#issuecomment-39379160
.

@lhotari
Copy link

lhotari commented Apr 3, 2014

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
Copy link
Collaborator

@lhotari I agree, shell function could be a solution to update JAVA_HOME on directory change.

@kellizer Which tools do you have in mind? At this time, specifics tools that need JAVA_HOME are supported with plugins ( jenv enable-plugins ).

@kellizer
Copy link
Author

kellizer commented Apr 3, 2014

@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:

@lhotari https://github.com/lhotari I agree, shell function could be a
solution to update JAVA_HOME on directory change.

@kellizer https://github.com/kellizer Which tools do you have in mind?
At this time, specifics tools that need JAVA_HOME are supported with
plugins ( jenv enable-plugins ).

Reply to this email directly or view it on GitHubhttps://github.com//issues/44#issuecomment-39432365
.

@gcuisinier
Copy link
Collaborator

Yes, I do this everyday too ..
"javac" use the selected JDK, maven/ant too (if you enable the plugin).

The only part you don't have directly is shell script using JAVA_HOME explicitly.
You have to create a plugin, or use jenv exec for this script.

@niels1voo
Copy link

Intellij IDEA needs this too. It should be a given that you set JAVA_HOME.

@c0nscience
Copy link

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 mvn spring-boot:run via java exec. then the enforcer plugin knows which java version to use.

@c0nscience
Copy link

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:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

despite I enabled the maven plugin for jenv.

@gcuisinier
Copy link
Collaborator

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
jenv versions
echo $PATH

@c0nscience
Copy link

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 maven -version with jdk8 set via jenv.
Besides I installed it via homebrew, because it seems to be a more convenient way.

jenv version:
oracle64-1.8.0.05 (set by /Users/bherzig/Workspace/java/jhipster8-test/.java-version)

jenv versions:

  system
  oracle64-1.7.0.51
* oracle64-1.8.0.05 (set by /Users/bherzig/Workspace/java/jhipster8-test/.java-version)

echo $PATH:

/Users/bherzig/.rvm/gems/ruby-2.1.0/bin:/Users/bherzig/.rvm/gems/ruby-2.1.0@global/bin:/Users/bherzig/.rvm/rubies/ruby-2.1.0/bin:/usr/local/bin:/usr/local/opt/jenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/bherzig/.rvm/bin

@gcuisinier
Copy link
Collaborator

I've published a new version of jenv in homebrew. Could you upgrade and run 👍

jenv doctor

Thanks

@c0nscience
Copy link

Hi,
sorry for the late response.

I upgraded jenv with homebrew and run jenv doctor. At the first run I got this output:

[OK]    No JAVA_HOME set
[ERROR] java binary in path is not he the jenv shims
[ERROR] Please check your path
    PATH : /usr/local/Cellar/jenv/201404260/libexec/libexec:/Users/bherzig/.rvm/gems/ruby-2.1.0/bin:/Users/bherzig/.rvm/gems/ruby-2.1.0@global/bin:/Users/bherzig/.rvm/rubies/ruby-2.1.0/bin:/usr/local/bin:/usr/local/opt/jenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/bherzig/.rvm/bin
[OK]    Jenv is correlly loaded

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.

@gcuisinier
Copy link
Collaborator

Could you provide me the output of

command - v java

@c0nscience
Copy link

Here is the output of command -v java:
/usr/local/opt/jenv/shims/java

@c0nscience
Copy link

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.

@sshaw
Copy link

sshaw commented Aug 20, 2014

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 on JAVA_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 type jenv exec ruby a_program.rb.

jenv should be transparent.

@gcuisinier
Copy link
Collaborator

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.
So this solution works perfectly for ruby.

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.
And I had no time for this.

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 !
But do not hesitate to propose improvement, it's an OpenSource project.

@sshaw
Copy link

sshaw commented Aug 21, 2014

I agree, but jenv is made on the base of rbenv. rbenv use the "wrapping-way" to run the selected binaries.

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.

I am not a ruby user, but I think they don't have an equivalent en JAVA_HOME.

Yes, there is no JAVA_HOME equivalent in Ruby.

Doesn't setting JAVA_HOME eliminate the need to have the shims directory and the plugins (to some extent)? If setting one variable can eliminate code and provide transparency to the users and tools I see no downside.

Any contribution I would make would set JAVA_HOME. But first, I'm going to see if the other jenv does this for me...

@sshaw
Copy link

sshaw commented Aug 21, 2014

Also I would mention that you do not set JAVA_HOME in the docs. As a first time user, jenv caused some strange problems that turned out to be related to... JAVA_HOME not being set.

@dattatre263
Copy link

$ echo $PATH
/Users/CHI\dparupud/.jenv/shims:/Users/CHI\dparupud/.jenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/apache-maven/apache-maven-3.1.1/bin

@gcuisinier
Copy link
Collaborator

Mmm .. there is a bug somewhere.
Can you list

`ls /Users/CHI\dparupud/.jenv/shims``

I presume that mvn wrapper shim is not correctly created

@dattatre263
Copy link

@gcuisinier, thanks for all your help.
I thought maybe because of CHI\ ( backslash) was causing all this issue. I recreated my account on my mac.

Now my ~ ( home) points to
/Users/dparupud.

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.

@dattatre263
Copy link

I think my problem is solved. Thanks for all your help

dparupudi-mac:~ dparupud$ jenv global oracle64-1.8.0.31
dparupudi-mac:~ dparupud$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
dparupudi-mac:~ dparupud$ mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/local/apache-maven/apache-maven-3.1.1
Java version: 1.8.0_31, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"
dparupudi-mac:~ dparupud$ jenv global oracle64-1.6.0.65
dparupudi-mac:~ dparupud$ mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/local/apache-maven/apache-maven-3.1.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

@ihliedaily
Copy link

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:

↪ jenv doctor Mo 30 Mär 2015 19:19:13 CEST [OK] No JAVA_HOME set [OK] Java binaries in path are jenv shims [ERROR] Jenv is not loaded in your fish [ERROR] To fix : cat eval "$(jenv init -)" >> your profile

↪ echo $PATH Mo 30 Mär 2015 19:19:15 CEST /Users/swn/.jenv/shims /Users/swn/.jenv/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin

↪ jenv shell Mo 30 Mär 2015 19:19:51 CEST jenv: no such command "shell"

↪ jenv enable-plugin maven Mo 30 Mär 2015 19:20:27 CEST jenv: no such commandenable-plugin'`

↪ ls /Users/swn/.jenv/shims Mo 30 Mär 2015 19:20:31 CEST appletviewer idlj java javafxpackager javaws jdb jmap jrunscript jstat keytool pack200 rmid serialver unpack200 xjc apt jar javac javah jcmd jhat jmc jsadebugd jstatd native2ascii policytool rmiregistry servertool wsgen extcheck jarsigner javadoc javap jconsole jinfo jps jstack jvisualvm orbd rmic schemagen tnameserv wsimport

`↪ 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
set PATH /Users/swn/.jenv/shims $PATH

jenv rehash 2>/dev/null

set JENV_LOADED 1
set JAVA_HOME
`

and last:

↪ jenv global 1.6
↪ java -version java version "1.7.0_75" Java(TM) SE Runtime Environment (build 1.7.0_75-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

What am i missing? (it's the same with or without oh-my-fish)

@solidjb
Copy link

solidjb commented Apr 13, 2015

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)

@mcandre
Copy link

mcandre commented Oct 9, 2015

+1 Same behavior on my machine, with multiple command line applications and with IntelliJ.

@Aiglobelam
Copy link

Hello there, have not read all comments about how to handle $JAVA_HOME... But I followed @solidjb example and it worked like a charm.

@fvm
Copy link

fvm commented Feb 4, 2016

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.
To fix this, one should add the value to the system environment using: launchctl setenv JAVA_HOME "$(jenv javahome)". I've put this in my own .zshrc (or in case of bash .bash_profile) right behind the eval "$(jenv init -)" line, but this should ideally be in a plugin (specifically for OS X).

@snimavat
Copy link

sdkman needs JAVA_HOME.. but jenv doesnt set it..

@gcuisinier
Copy link
Collaborator

You can set JAVA_HOME (and JDK_HOME) by enabling the export plugin

jenv enable-plugin export

@danielsotopino
Copy link

@gcuisinier that totally did the job

@mehrad-rafigh
Copy link

When i do jenv enable-plugin export I get

jenv: no such command `enable-plugin'

Gonna go delete jenv from my machine....

@danielsotopino
Copy link

what version of jenv do you have ?

@nardras
Copy link

nardras commented Apr 14, 2017

same here - version is jenv 0.4.4

@berezovskyi
Copy link

Maven 3.5 was picking up 9-ea irrespective of the jenv config. jenv enable-plugin export solved the problem.

@HaoH
Copy link

HaoH commented Jan 25, 2018

add the following line in .zsh or .bashrc
export JAVA_HOME="$(jenv prefix)
after
if which jenv > /dev/null; then eval "$(jenv init -)"; fi

@raymondjplante
Copy link

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 a jenv global x.y.z?

@AmmarHasan
Copy link

@HaoH you forgot to put " at the end of the line

export JAVA_HOME="$(jenv prefix)"

Thanks, it worked

@kyounger
Copy link

When running jenv global x.y.z (local, neither) it doesn't seem to automatically update JAVA_HOME in the current shell.

@MicahLC
Copy link

MicahLC commented Feb 21, 2019

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 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 👍

@Skoti
Copy link

Skoti commented Mar 5, 2019

jenv doctor
[OK]	JAVA_HOME variable probably set by jenv PROMPT
[OK]	Java binaries in path are jenv shims
[OK]	Jenv is correctly loaded
java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 1.8.0_202, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre
Default locale: en_PL, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"

So these above seem to work but when I run sdkmanager I get:
Error: Could not find or load main class java.se.ee
Which means it still uses java 11 which does not have ee modules.
Same error when I execute jenv exec sdkmanager, same when I execute gradle or jenv exec gradle. Even though gradle plugin (in jenv) is enabled.
And same when I run ./gradlew some_command in Android Studio terminal.

My jenv versions:

  system
  1.8
  1.8.0.202-ea
  11.0
  11.0.2
  openjdk64-11.0.2
* oracle64-1.8.0.202-ea (set by /usr/local/var/jenv/version)

My path:

/Users/{redacted_user}/.rbenv/bin:/Users/{redacted_user}/.rbenv/shims:/usr/local/var/jenv/shims:/usr/local/sbin:/usr/local/opt/maven/bin:/usr/local/opt/gradle/bin:/usr/local/opt/ant/bin:/usr/local/share/android-sdk/tools:/usr/local/share/android-sdk/platform-tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/{redacted_user}/.nodebrew/current/bin:/Users/{redacted_user}/.rbenv/bin:/Users/{redacted_user}/.rbenv/shims:/usr/local/var/jenv/shims:/usr/local/sbin:/usr/local/opt/maven/bin:/usr/local/opt/gradle/bin:/usr/local/opt/ant/bin:/usr/local/share/android-sdk/tools:/usr/local/share/android-sdk/platform-tools:/Users/{redacted_user}/.jenv/bin

Any thoughts?

@ati90ati
Copy link

ati90ati commented Nov 14, 2019

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

@astubbs
Copy link

astubbs commented Nov 21, 2019

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)

@nicechester
Copy link

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.

jenv disable-plugin maven
jenv disable-plugin export
jenv enable-plugin maven
jenv enable-plugin export

I actually, opened up new terminal after disabling plugins and continued there.
Hopefully, it helps someone else having same issue with me.

@adrian-skybaker
Copy link

adrian-skybaker commented Feb 23, 2021

Any reason the export plugin isn't enabled by default?

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).

@cglacet
Copy link

cglacet commented Aug 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests