0

I have an application that's built in grails 2.1
My environment variables are set to point to JAVA 8 and Grails 3.8 along with the path.
I am aware of the fact that grails 2.1 has support upto Java 6. But I donot want to make changes to my environment variables in order to make it point to Java 6.

So I tried to set home and path for java 6 and grails 2.1 via command line. I was successful in doing so and echoe %JAVA_HOME%, %GRAILS_HOME% and %PATH% did show that values were set correctly.

Trying to run the app with grails run-app command from under the project's root directory throws below error :

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/grails/cli/GrailsCli : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.grails.cli.GrailsCli.  Program will exit.

I tried to write a batch script that would set the %JAVA_HOME%, %GRAILS_HOME% and %PATH% to Java 6 and Grails 2.1 specific locations and then execute "grails run-app" from under the project's root directory, but while executing the script I got the same above error.

Below is how my batch script looks like:

set JAVA_HOME=C:\Softwares\Java\Java-6\jdk1.6.0_41
set PATH=%PATH%;%JAVA_HOME%\bin

set GRAILS_HOME=C:\Softwares\Grails\Grails_2.1.0
set PATH=%PATH%;%GRAILS_HOME%\bin

cd /D C:\MyWorkspace\MyApplication

grails run-app

REM pause

I have never written a batch script before.So, please correct me where possible.

Also, as for some restrictions in place I do not have the freedom of installing SDKMan.

Any guidance in this regard is greatly appreciated.

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • Sorry, why again do you intend versions that seriously outdated? – GhostCat Aug 19 '18 at 06:35
  • @GhostCat You are right. Is kind of a legacy application. So can't help it. I need to find a workaround. – Asif Kamran Malick Aug 19 '18 at 07:13
  • I don't have much time right now. For the record: you understand the exception? It is telling you that you try to use a class within a jvm, but the class was compiled for a newer jvm. Are using the wrong GRAILS version? – GhostCat Aug 19 '18 at 07:31
  • run "java -version" before grails run-app. What is the output? – Rcordoval Aug 19 '18 at 07:48
  • @GhostCat Thanks a lot for your time. What I understood from the exception is that it needs a different java runtime. But I dig more into it and found a better explanation [here](https://stackoverflow.com/questions/20690143/java-unsupported-major-minor-version-51-0) and [here](https://en.wikipedia.org/wiki/Java_class_file#General_layout). I am new to this grails framework. The version used i nmy project is **app.grails.version=2.1.0** atleast this is what my application.properties says. – Asif Kamran Malick Aug 19 '18 at 08:06
  • @Rcordoval runnin java -version(in the same window where I run the script) gives me the one set in my system environmen tvariable, i.e. `java version "1.8.0_60"` `Java(TM) SE Runtime Environment (build 1.8.0_60-b27)` `Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)` – Asif Kamran Malick Aug 19 '18 at 08:08

1 Answers1

1

It seems you have to set environment variable in front of the existing PATH setting:

set PATH=%JAVA_HOME%\bin;%PATH%;

This will lookup at the first match (the wanted version)}

Also, make sure you are using the exact same version of compile

Rcordoval
  • 1,932
  • 2
  • 19
  • 25
  • Oh yes, you are right. placing the existing path after %JAVA_HOME%\bin made it work. The application is up and running now. So basically, what I understood is that the sequence does matter. Thanks again for pulling me out of this trouble. – Asif Kamran Malick Aug 19 '18 at 08:46