0

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.

Keen Sage
  • 1,899
  • 5
  • 26
  • 44
  • You are not losing your mind, nor do you have an obvious configuration problem like most of the solutions below propose. This is a real issue when upgrading GGTS to use a new version JVM once it has built and run projects with the older JVM. When doing a run-app from within GGTS you are actually going through two levels of grails processes. The problem is that the *second* instance that is launched by the standing grails gets the wrong version. Where it gets the configuration to launch that instance is the issue and I can't find it. It comes from some environment setting in eclipse. – Steve Hole Dec 18 '15 at 18:01

4 Answers4

2

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.

Kris
  • 3,898
  • 1
  • 23
  • 32
  • I actually verified that. but I am not sure why it is still picking up java-7-openjdk-amd64. – Keen Sage Apr 29 '14 at 17:39
  • Not sure what you mean by 'picking up'. Eclipse and STS only 'picks up' the default JVM for your workspace once, the first time you open/create the workspace. This is a workspace preference so it will then be stored 'permanently' in the workspace, where you can change it via the preferences. I think the first time it will default to using the same JVM that Eclipse / STS is running with... – Kris May 22 '14 at 16:52
  • ... and you can change the VM eclipse is running with by editing STS.ini file as in VAdimo's answer. Just be aware that the STS.ini will only change the JVM eclipse runs with and the default VM in *new* workspace but not existing workspaces. – Kris May 22 '14 at 16:54
0

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.

Vad1mo
  • 5,156
  • 6
  • 36
  • 65
  • This also didn't work. Here is the link to the configuration and .ini file content. https://gist.github.com/sashwatp/5246eb4473299109fbd0 – Keen Sage May 04 '14 at 15:37
  • There is a strange behavior. It would work fine after re-installation but just 1 time. The error would start showing up again after restart. – Keen Sage May 04 '14 at 15:40
0

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.

Vad1mo
  • 5,156
  • 6
  • 36
  • 65
0

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 (e.g. 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 (e.g. 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!

hko19
  • 1,054
  • 4
  • 16
  • 25