0

I have created a runnable JAR file using Eclipse in one machine, say computer A. Computer A's Java version is,

java version "1.8.0_102" java(TM) SE Runtime Environment (build
1.8.0_102-b14) Java HotSpot(TM) Client VM (build 25.102-b14, mixed mode)

Now, I am trying to run this JAR file in another machine, say computer B, using the java -jar command in the command prompt. However, it gives the following error.

Exception in thread "main" java.lang.UnsupportedClassVersionError: bbg_upload/Task2_DailyValMktCap : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)

Computer B's Java version is lower than computer A's.

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode)

How can I run my JAR file in computer B without messing with any of the settings of computer B (i.e. without updating the JRE, etc.) because I am not allowed to modify anything in computer B since it is a common computer.

Krish
  • 319
  • 4
  • 19
  • You must use the Java version with which it was compiled. So you must install Java 8 on the target machine (here: B). – Seelenvirtuose Sep 21 '16 at 07:08
  • Hii @ Seelenvirtuose, I don't actually want to mess with the target machine's settings since it is a common machine. It's too risky that I might affect other things when I update the Java version of that machine. – Krish Sep 21 '16 at 07:10
  • You can set the 'Java Compiler' compliance to 1.6 in the Eclipse project properties - but you will also have to make sure you don't use any classes or language features that have been added since 1.6 – greg-449 Sep 21 '16 at 07:13
  • You can compile your project with lower language level than you have at computer A. For command line compiler it would be the parameter: javac -target 1.6. For eclipse you have to set project settings properly. – mv200580 Sep 21 '16 at 07:15
  • Hi! Thank you so much for your comments. I installed JDK 1.6 set the project properties to use 1.6 in eclipse, then created a runnable jar with this. It perfectly ran on computer B. – Krish Sep 22 '16 at 05:38

1 Answers1

0

Because of Java version mismatch, in computer A you must build with JDK 1.6 compliance. You can compile with JDK 1.6 like that:

  • Project -> Properties
  • Java Build Path : in Libraries tab, ensure that you are really using jre6
  • Java Compiler : Ensure that you are using 1.6 compliance
Lucas Pham
  • 26
  • 4
  • Thank you@Lucas Pham. I installed JDK 1.6, set the project properties to use 1.6 in eclipse, then created a runnable jar with this. It perfectly ran on computer B. – Krish Sep 22 '16 at 05:39