How to make grails choose the right JDK?

I am using Mac OSX 10.8.5 with Oracle Java 1.7 installed in addition to mac 1.6. I have my set of JAVA_HOME and JAVA_HOME / bin in front of my path. When I run grails, compile from the command line, I see that it selects Java 1.6 instead of 1.7. How to make grails command line command select 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) 
+6
source share
5 answers

What shell are you using and how exactly did you install JAVA_HOME ? Grails should respect your JAVA_HOME parameter while it is displayed by the grails , for example, in bash you should export instead of a variable, and not just for it, tcsh use setenv and not 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 since /usr/bin/java will automatically delegate the corresponding java command for the current JAVA_HOME .

+3
source

If you want to localize the Java version only for Grails, the best way is to edit the file below,

 .gvm/bin/gvm-init.sh 

You can set JAVA_HOME in this file as shown below.

 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home 

I have Java 8 on my machine, and here I install java 1.7 for grails ONLY.

+1
source

For the new SDKman method, you can export JAVA_HOME to [YOUR HOME]/.sdkman/candidates/grails/[concrete version or current]/bin/grails

+1
source

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 some things made this difficult:

  • I would install Java 8 as the default version after installation with sudo apt-get install oracle-java8-set-default , but 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 replacing the JDK.
  • This file worked, but the aforementioned env vars overshadowed things too much.

In the end, I removed both of the above elements from my environment and the files in /etc/profile.d , and now:

  • Modify the JDK by running sudo update-java-alternatives -s java-8-oracle (or java-7-oracle ) as described in the webupd8 article;
  • Run gvm to set the current or default rake and other tools as needed.

It seems pathetic than it should be, but I think it works now.

0
source

If you use SDKMAN to install Grails (this is the currently recommended method ), you can add any version of Java that you installed in SDKMAN and they will manage them for you as well. For instance:

 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 do not want you to consider one of the other options.

 $ echo $JAVA_HOME /home/user/.sdkman/candidates/java/current 

For More Information: Local SDKMAN Versions

0
source

Source: https://habr.com/ru/post/954165/


All Articles