Unable to run Grails 2.1 with path set to Java 6 - java

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.

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

Related

Web project not running on server on Mac OS X in Eclipse Mars

I have Java 8 (JDK and JRE 8) on my machine. I have Eclipse Mars 4.5.1 .
I am trying to create a simple Static Web Project and while running the project on HTTP Preview (or a Dynamic Web Project on Apache Tomcat for that matter), it gives the following error. (Also see the screenshot attached.)
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/server/Handler : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
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)
The problem is that you're using JDK1.8 to compile your code (with target runtime of 1.8).
However, your server is configured to run with JDK 1.6 (you can see it at the top of the console window [ HTTP preview at...])
Change your workspace default JRE to your JDK 1.8 if you want to use the http preview (I tried and saw no option to specify a runtime JRE).
If you want to use tomcat, then specify the correct JRE on the first page of the 'New Server' wizard.

NoClassDefFoundError while running on 64bit machine

I am getting the following exception while service startup on a 64bit Machine.
But the code runs fine on a 32bit machine.
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
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)
at org.springframework.context.support.GenericApplicationContext.<init (GenericApplicationContext.java:103)
at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:125)
at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:41)
at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:35)
at org.springframework.coral.DisposableApplicationContext.<init>(DisposableApplicationContext.java:16)
at com.amazon.coral.spring.Launcher.<init>(Launcher.java:85)
at com.amazon.coral.spring.Launcher.main(Launcher.java:56)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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)
... 19 more
Unless you (or the libraries you use) are using native code, the underlying platform is very seldom the problem in Java programs.
From the Javadoc of NoClassDefFoundError (http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html):
Thrown if the Java Virtual Machine or a ClassLoader instance tries to
load in the definition of a class (as part of a normal method call or
as part of creating a new instance using the new expression) and no
definition of the class could be found.
The searched-for class definition existed when the currently executing
class was compiled, but the definition can no longer be found.
So it was present when the code was compiled, but not anymore when you try to run it elsewhere. The single-most typical reason for this is that the classpath is incorrectly set up, usually by not having the jar-file containing the class in question is not in the classpath. Revise your classpath definition and rerun.
If you are unfamiliar with how the classpath works I can strongly recommend reading up on the Oracle Java Tutorial.
99% likelihood is that you have a CLASSPATH environment variable on the machine where it runs, and not on the machine where it doesn't. If you're starting from a service on the latter and the command-line on the former, make that 99.9%.
Check your JAVA_HOME environment variable. If your are using eclipse IDE, check your IDE's Java Build Path.
Same problem I'm facing. I resolved the problem by adding the following 2 jar files:
asm-all 2.2.3.jar
cglib-nodep 2.1_3.jar
and remove the asm.jar and cglib.jar from the machine (64bit) where I got error.
But my question is why this problem exits in that machine. I checked CLASSPATH, PATH and JAVA_HOME environment varibles. But all are same in the two machine.
Same problem I'm facing. I resolved the problem by adding the following 2 jar files:
asm-all 3.3.1.jar
cglib-nodep 2.1.3.jar
and remove the asm.jar and cglib.jar in lib

Tomcat versions aren't starting

Just downloaded Tomcat 7.0.26, unzipped it, ran the startup.bat file and it failed with the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
... 1 more
A co-worker recommended I try using an older/more stable version of Tomcat. He's running 6.0.35, so I decided to try that.
I did the same exact thing with 6.0.35...and the same thing is happening to me...
What is going on here?!?! I see in bin/tomcat-juli.jar that the LogFactory is there (both versions)...
Edit:
Here are the values for several environment variables:
CLASSPATH: .;C:\Users\<myUser>\Desktop\jars\;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
JAVA_HOME: C:\Program Files\Java\jdk1.6.0_25
These don't seem to add up!?! If I'm reading this correctly, doesn't it say that the CLASSPATH thinks I'm using jre6, but that Java Home is set to jdk1.6.0_25?
It's possible that some environment variable is set in your system which is preventing Tomcat from running.
Check:
CATALINA_HOME
CATALINA_BASE
CATALINA_OPTS (for classpath additions)
JAVA_OPTS (for classpath additions)
and less likely:
LOGGING_CONFIG
LOGGING_MANAGER
If any of these environment variables are set, correct or unset them. My guess is that CATALINA_HOME is set to point to a different version of Tomcat on your system.
I have downloaded Tomcat 7.0.26 2 hours ago and its working fine. It looks like you have an old version of commons-logging.jar anywhere in your classpath (path variable, jre versions/lib, etc...).
I had same problem.
All I did was to copy all the jar files in [apache-tomcat]/lib directory and all the jar files in [apache-tomcat]/bin to [jdk directory]/jre/lib/ext directory.
This should solved the problem.

Mac OS X tries to launch jar with Java 1.5 although it needs 1.6

I have a Java project which uses Java 1.6. I package a jar, the manifest simply states the Main-Class.
On the Mac, it fails to start since it tries to use 1.5 for it:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)
Can I specify the 1.6 in the jar or do I need to alter the settings on the Mac?
Just start it by calling the correct java runtime from a JDK/JRE 6 installation, if you don't want to change default settings (although I would recommend to switch to Java 6).

How to invoke groovy with 'java' from command line

I have to ship some groovy code to some users that have only java installed (no grooy, no $groovy_home, etc). I'm trying to invoke groovy from the commandline but I'm having no luck. Here's my bat file:
java -classpath .;lib;bin;bin-groovy introspector.AclCollector
And here's my exception:
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 12 more
Could not find the main class: introspector.AclCollector. Program will exit.
Does anyone have a clue? I have 'groovy-all-1.6-beta-1.jar' in \lib dir.
You have here another example of Groovy app called from Java (in this case, from ant, but the general idea is the same).
java -cp [...];%GROOVY_HOME%/embeddable/groovy-all-1.5.4.jar;[..]
As mentioned by frankowyer, you have the exact groovy jar explicitly listed on the classpath arguments of the java.
Since your clients do not have special environment variable, just replace the %GROOVY_HOME%/... with the complete path to:
groovy.jar or
goovy-all-VERSION.jar (to minimize any conflict with other libraries)
I think you need to explicitly list the groovy jar in the classpath
One way to avoid problems with different class paths on different machines would be to bundle all the necessary dependencies into one single jar, this would also make distribution to users easier. This can be done with this 'GroovyWrapper' script. The default jars (embeddable/groovy-all-.jar and lib/commons.jar) are included by default in the script and if you require other JARS they can easily be added.
See http://docs.codehaus.org/display/GROOVY/WrappingGroovyScript for the full script and instructions.
Here's an example of how to use GroovyWrapper:
Say you have groovy script HelloWorld.groovy, use GroovyWrapper for building HelloWorld.jar, as follows:
$ groovy GroovyWrapper -c -m HelloWorld
GroovyWrapper will compile the script HelloWorld.groovy to HelloWorld.class, and creates a self-executable jar HelloWorld.jar.
Now you can use the HelloWorld.jar for launching the HelloWorld script, simply by running:
$ java -jar HelloWorld.jar
GREAT ANSWER by VonC:
....... Since your clients do not have special environment variable,
just replace the %GROOVY_HOME%/... with the complete path to:
groovy.jar or
goovy-all-VERSION.jar (to minimize any conflict with other libraries)........
this is for windows Vista:
In System Properties | Environmental Variables | User variables:
Variable Name GROOVY_HOME set to C:\groovy\Groovy-1.8.5
and the Variable Name CLASSPATH value's set to include .;%GROOVY_HOME%\embeddable\groovy-all-1.8.5.jar
Don't make the mistake I did(spinning my wheels a bit), of not prep-ending the path of the 'groovy-all' with ".;" (dot and semi-colon): as the path needs the base folder you're in for finding the main class(strange as it seems)
Watch out of [~]!
java -cp .:~/path-to-groovy-all.jar YourClassName # does not work
java -cp ~/path-to-groovy-all.jar:. YourClassName # works
java -cp .:/full/path/to/goovy-all.jar YourClassName # works
In first line tilde is not processed by bash, and java can not understand it.
In second line tilde is replaced by bash and everything works fine.

Categories