2

I have a jar file named umar.jar in /root/umar/bin directory. I have a shell script file run.sh in same directory. Following is the content of run.sh

#!/bin/bash
"$JAVA_HOME"/bin/java -jar /root/umar/bin/umar.jar

Now when I run the shell script, I get the following error

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

After some googling, I found (as a folk from stackoverflow mentioned) that such errors occur when the Jar was compiled with a later version of the JDK than your JRE.

Now strange thing is, if I run this command directly on shell

java -jar umar.jar

it works perfectly fine. If the jar was compiled with a later version of JDK than my JRE, it shouldn't have had run at all even from the shell.

What do you suggest?

1
  • In the shell, type 'whereis java' or 'whereis javac' and compare it with 'echo "$JAVA_HOME"'. They should tell you the paths to the JRE. Commented Oct 20, 2009 at 2:28

3 Answers 3

4

compare "java -version " and ""$JAVA_HOME"/bin/java -version"

You probably have multiple JVMs installed

Sign up to request clarification or add additional context in comments.

Comments

1

As already mentioned - you're trying to use byte code compiled by the later compiler with old jvm.

Please note that if your PATH contains multiple java executables of different versions you can switch between them easily using '-version' key.

Suppose you have java5 and java6 at your PATH and java5 is located before java6 there. You can see that java5 is used by default then (if you execute 'java -version' it prints corresponding information). However, you can start java6 easily using command like 'java -version:1.6 ...' (e.g. if you execute 'java -version:1.6 -version' you see that java6 is used).

Comments

0

Export the java and jre home which you need to use in your sh file.

Run the jar using the exported java home

e.g

export JAVA_HOME=/opt/java6
export JRE_HOME=/opt/java6/jre
/opt/java6/bin/java -Xms2048m -Xmx2048m -jar abc.jar $1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.