简体   繁体   中英

GGTS picking incorrect java path

The GGTS(Groovy Grails Tools Suite) is picking the incorrect value of JAVA_HOME. When I check the value in terminal it shows java-6, but GGTS is picking java-7.

sashwat@sashwat-desktop:~$ echo ${JAVA_HOME}
/usr/lib/jvm/java-6-openjdk-amd64

I am getting the following error in GGTS

Error executing script TestApp: java.io.IOException: 
Cannot run program "/usr/lib/jvm/java-7-openjdk-amd64/bin/java" (in directory "/home/sashwat/grails/gTunes"): 
java.io.IOException: error=2, No such file or directory (Use --stacktrace to see the full trace)

I am able to run the app from command line, it is only giving error when I try to run it from GGTS. Can someone help me in this regard?

There is a strange behavior. If I re-install the GGTS, everything would work fine but after restart it would start showing the above error.

STS doesn't use 'JAVA_HOME' to determine what JVM to execute Grails commands. Like most Eclipse based tools it is instead configured via workspace settings. To change the JVM for executing grails commands use menu:

Window >> Preferences.

Go to

Java >> Installed JREs

Then make sure to add the JVM you want to use (if not already there) and ensure it is checked as the default.

When you start eclipse then the system defined JRE is used by default. The eclipse JAVA_HOME is ignored.

You can see here which JRE/JDK eclipse is using. Help -> About Eclipse -> Installation Details -> Configuration

If you wand to start eclipse with a special JRE/JDK like the one in your JAVA_HOME you have to modify the eclipse.ini or sts.ini file (normally it is next to the eclipse executable).

add the path to your javaw before the -jvmargs in your ini file.

-vm
"C:\Program Files\Java\jdk1.6.0_16\bin\javaw.exe" 
-jvmargs
...

Restart eclipse and verify the java version.

For each project you can choose what JRE/JDK eclipse should use to compile and execute.

  1. You need to tell eclipse where to find all your JREs and JDKs on you system.
    • Go to Preferences->Java->Installed JREs
    • Add or Search all your JRE/JDKs so that their appear in the list
  2. (Optional but recommended) Select for each execution Environment 1.6, 1.7, 1.8 the matching JDK/JRE you searched before.
  3. Now You can define which JRE/JDK Eclipse should user for your Project. In Packe Explorer right click on you Project and select properties. Next
    • Go to Java Build Path and Edit the current JRE under libraries
    • (Depends on step 2)You can now choose the execution Environment 1.6, 1.7, 1.8 or
    • Choose from the list of Alternate JRE you favorite JRE/JDK

Thats should do it. No you should see in package explorer that the jre changed. If you now execute your code then provided jre is used.

If you had multiple Java versions installed on your dev machine, and if you had exhausted all possible ways of configuring to use the right Java version in GGTS but to no avail, you'd be very frustrated.

Unfortunately, under rare cases that your Grails in GGTS is still picking up the wrong older version (eg 1.6) when it should pick up the newer one (1.7), and all indicators in the GGTS say GGTS is configured for the project to use the newer Java version, but it's actually not reflecting your setup.

How do you know it's not? Because when I ran Grails command (eg grails compile) from within GGTS, I got:

Unable to load extension class [org.codehaus.groovy.runtime.NioGroovyMethods]

which let me to believe that Java older version (1.6) was still mistakenly being used by GGTS for some reason. When I run the following from the command line out side of GGTS:

cd <project directory>
grails compile

I got the project compiled successfully with no problem. What's going on?

In my case, I doubt that my older GGTS version has been upgraded in-place all the way to the latest but somehow the GGTS was not as clean as a fresh reinstall. Therefore, the solution for me was to re-install the latest GGTS, then the problem just went away cleared!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM