Reputation: 4348
I'm using Mac OSX 10.8.5 with Oracle's Java 1.7 installed in addition to the mac's 1.6. I have my JAVA_HOME set and the JAVA_HOME/bin in the front of my path. When I run a grails compile from the command line I can see it's choosing the Java 1.6 instead of 1.7. How do I make the grails command-line choose the JDK I want?
➤ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
➤ echo $PATH
/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin /usr/local/share/npm/bin /Users/kbrodhagen/bin /Users/kbrodhagen/.rvm/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /opt/X11/bin /usr/local/git/bin
➤ set -x JAVA_OPTS "-showversion"
➤ grails compile
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
Upvotes: 6
Views: 12569
Reputation: 15995
If you use SDKMAN to install Grails (which is the currently recommended method), you can add any versions of Java you have installed to SDKMAN and it will manage them for you as well. For example:
sdk install java openjdk-8 /usr/lib/jvm/java-8-openjdk-amd64
sdk use java openjdk-8
Note that this will set JAVA_HOME
for your user, so if you don't want that you may want to consider one of the other options.
$ echo $JAVA_HOME
/home/user/.sdkman/candidates/java/current
For more information: SDKMAN local versions
Upvotes: 0
Reputation: 11
For the new SDKman method you can export JAVA_HOME
in [YOUR HOME]/.sdkman/candidates/grails/[concrete version or current]/bin/grails
Upvotes: 1
Reputation: 5029
I needed to be able to switch between a Java 7/Grails 2.4.4 project and a Java 8/Spring 4 project in Ubuntu 12.04 and certain things made this difficult:
sudo apt-get install oracle-java8-set-default
, but that apparently creates /etc/profile.d/jdk.sh
and /etc/profile.d/jdk.csh
containing JAVA_HOME
, JRE_HOME
and other env vars that prevented me from swapping the JDK.In the end, I removed both of the above items from my environment and the files in /etc/profile.d
and I now:
sudo update-java-alternatives -s java-8-oracle
(or java-7-oracle
) as mentioned in the webupd8 article;gvm
to set the current or default grails and other tools as requiredSeems messier than it should be, but I think it is working now.
Upvotes: 0
Reputation: 11
If you want to localise the Java version only to Grails the best way is to edit below file,
.gvm/bin/gvm-init.sh
You can set the JAVA_HOME in this file as below,
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
I have Java 8 in my machine and here I am setting java 1.7 for grails ONLY.
Upvotes: 1
Reputation: 122394
Which shell are you using and exactly how did you set JAVA_HOME
? Grails should respect your JAVA_HOME
setting as long as it is visible to the grails
command, for example in bash you must export
the variable rather than just setting it, in tcsh
you would use setenv
rather than set
.
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
You can also remove /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin
from your PATH as /usr/bin/java
will automatically delegate to the appropriate java
command for the current JAVA_HOME
.
Upvotes: 3