简体   繁体   中英

Executing runnable jar from command prompt with complete Java path

To execute a jar command is >java -jar jar-file-name.jar

It works fine if JAVA_HOME version matches with the JDK version using which jar file was build. Otherwise it gives below error.

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:626)
        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:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)

I have got a third party jar built in JDK 1.8 upon which I dont have any control to change the JDK verison and rebuilt.

I have got a unix machine in whih JAVA_HOME is set to JDK 1.5. and my application one of several other applications deployed in same machine. So I cant change the JAVA_HOME to point to JDK 1.8 which may break other applications.

I know the path where JDK 1.8 is installed in the system.

Is there a way to refer JDK complete path (which is not set as JAVA_HOME) and execute the jar.

Any help would be highly appreciated.

/path/to/jdk/bin/java -jar jar-file-name.jar

so as i understand you do have 2 different java versions on your system and the 1.5 version is used as your default java. but for your new jar you need 1.8 to start?

you should use the absolute path to your 1.8 java in order to start it, like this:

/opt/java/1_8/bin/java -jar jar-file-name.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM