Skip to content

Problem with jenv and maven plugin #74

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

Open
antusus opened this issue Jan 7, 2015 · 15 comments
Open

Problem with jenv and maven plugin #74

antusus opened this issue Jan 7, 2015 · 15 comments

Comments

@antusus
Copy link

antusus commented Jan 7, 2015

I have set different Java version for my project. I'm building it using maven. I've enabled maven plugin in jenv but I have some troubles after rebooting machine. It sees that maven plugin is enabled but it causes maven to use wrong Java. I have to disable plugin and enable it again to work (see attached fragment from my terminal).

I'm using:
homebrew - 0.9.5
jenv - 0.4.0
maven - 3.0.5

Additionaly I have:
zsh + oh_my_zsh

➜  lp-base git:(develop) jenv enable-plugin maven
maven plugin already enabled
➜  lp-base git:(develop) jenv info java
Jenv will exec : /Users/kamilberdychowski/.jenv/versions/1.7/bin/java
Exported variables :
  JAVA_HOME=/Users/kamilberdychowski/.jenv/versions/1.7
➜  lp-base git:(develop) mvn --version
Picked up _JAVA_OPTIONS: -Dapple.awt.UIElement=true
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /usr/local/Cellar/maven30/3.0.5/libexec
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.1", arch: "x86_64", family: "mac"
➜  lp-base git:(develop) jenv disable-plugin maven
maven disabled
➜  lp-base git:(develop) jenv enable-plugin maven
maven plugin activated
➜  lp-base git:(develop) jenv info java
Jenv will exec : /Users/kamilberdychowski/.jenv/versions/1.7/bin/java
Exported variables :
  JAVA_HOME=/Users/kamilberdychowski/.jenv/versions/1.7
➜  lp-base git:(develop) mvn --version
Picked up _JAVA_OPTIONS: -Dapple.awt.UIElement=true
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /usr/local/Cellar/maven30/3.0.5/libexec
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.1", arch: "x86_64", family: "mac"
@fdlk
Copy link

fdlk commented Jan 7, 2015

I had the same problem, for me the issue turned out to be the file /etc/mavenrc which resets JAVA_HOME back to 1.7:

JAVA_HOME=`/usr/libexec/java_home -v 1.7`

I manually changed it to

JAVA_HOME=`/usr/libexec/java_home -v 1.8`

And that resolved the issue.

@antusus
Copy link
Author

antusus commented Jan 7, 2015

I have installed maven with homebrew. I couldn't find /etc/mavenrc. Never the less this solution is not sufficient for my need. I'm using java 8 in most places and one project requires java 7. I wanted jenv to set the proper java dependent on the project. And it is working until new shell is launched. I'll try to debug maven launching script. Maybe there is the answer.

@gcuisinier
Copy link
Collaborator

Could you provide output of 'jenv doctor' ?

@antusus
Copy link
Author

antusus commented Jan 7, 2015

➜ ~ jenv doctor
[OK] No JAVA_HOME set
[OK] Java binaries in path are jenv shims
[OK] Jenv is correctly loaded

@antusus
Copy link
Author

antusus commented Jan 7, 2015

I run rehash and it helped. Now maven picks proper Java. I thought I did executed rehash earlier but maybe I forgot. My mistake.

@antusus antusus closed this as completed Jan 7, 2015
@antusus antusus reopened this Jan 9, 2015
@fdlk
Copy link

fdlk commented Jan 9, 2015

Checking all possible places of a mavenrc for a sneaky JAVA_HOME setter may work. You need not change it, can also remove it cause jenv export plugin can set JAVA_HOME for you.

@antusus
Copy link
Author

antusus commented Jan 9, 2015

After rebooting of my mac the problem is showing again. Running jenv rehash solves it until next reboot.

@gcuisinier
Copy link
Collaborator

Could you give me output of
command -v mvn ?

@Sandmania
Copy link

Update: Nevermind. I missed one mavenrc that defined java home...

I seem to have the same problem. I'm trying to set a local java for maven to use, but am unable to do so.

OS X 10.10.5

$ brew --version
0.9.5 (git revision 7e0c5; last commit 2015-09-22)

$ jenv --version
jenv 0.4.3
$ pwd
/tmp/test
$ jenv doctor
[OK]    No JAVA_HOME set
[OK]    Java binaries in path are jenv shims
[OK]    Jenv is correctly loaded
$ jenv version
oracle64-1.8.0.60 (set by /tmp/test/.java-version)
$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
$ mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T19:29:23+02:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.7.0_21, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"
$ command -v mvn
/Users/user/.jenv/shims/mvn

Any ideas?

@gaetanlebrun
Copy link

I had the same problem and found a workaround by setting JAVA_HOME in ~/.mavenrc like this

JAVA_HOME=$(/usr/libexec/java_home -v $(jenv version-name))
$ pwd
/tmp/test-1.8
$ jenv local
1.8
$ mvn -v
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T04:57:37-07:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
$ pwd
/tmp/test-1.7
$ jenv local
1.7
$ mvn -v
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T04:57:37-07:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"

@stefanhendriks
Copy link

@gaetanlebrun after much googling and reading stack overflow/github whatnot. I could fix my maven / jdk issues with your suggestion. Thanks.

However, I did want to search further and noticed that /etc/mavenrc also did some overriding. Getting rid of that actually made jenv and mvn play nicely. Without the JAVA_HOME path setting by @gaetanlebrun .

However, when trying gradle I actually ran into this problem again and the JAVA_HOME fix also fixed that. The most ideal scenario would be to not set it like this, although not setting a JAVA_HOME at all feels quirky.

@mgazanayi
Copy link

@gaetanlebrun : Instead, I removed JAVA_HOME from ~/.mavenrc and everything is working fine.
Thanks for pointing that file 👍

@smgardner59
Copy link

I had this error after updating jenv. I ran the following 2 commands to get everything happy.
jenv disable-plugin export && jenv enable-plugin export
jenv disable-plugin maven && jenv enable-plugin maven

@eran12
Copy link

eran12 commented Jun 7, 2020

I have the same problem after updating.
After looking into the files inside ${userhome}/.jenv/shims/.
The exec command is pointing to the old version of jenv in my case it was 0.5.2 instead of 0.5.3

I didn't have any time to deal with it so I remove the folder and install fresh jenv from brew.

And of course adding manually all java installations.

Home brew version: 2.3.0

@carlitorendon
Copy link

I had this error after updating jenv. I ran the following 2 commands to get everything happy. jenv disable-plugin export && jenv enable-plugin export jenv disable-plugin maven && jenv enable-plugin maven

Thank you @smgardner59, that did it for me... weird

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

10 participants