Running a jar from shell script

57,280

Solution 1

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

You probably have multiple JVMs installed

Solution 2

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).

Share:
57,280
craftsman
Author by

craftsman

Frontend developer, loves building beautiful and interactive interfaces. Check out my latest jQuery plugin: www.eastros.com/frame-carousel/

Updated on October 16, 2020

Comments

  • craftsman
    craftsman over 3 years

    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?