Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make grails choose the right JDK?

Tags:

grails

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)
like image 492
kennbrodhagen Avatar asked Sep 19 '13 12:09

kennbrodhagen


2 Answers

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.

like image 172
Ian Roberts Avatar answered Sep 23 '22 09:09

Ian Roberts


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.

like image 27
Asanga Manage Avatar answered Sep 23 '22 09:09

Asanga Manage