0

Everyone!

I have a java program with jar libraries that works on the following JDK version:

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

I need to make it compile on a supercomputer that works on the following JDK version:

java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

As you can see they all have the same JDK which is JDK 8. However, when compiling using:

javac myFile.java 

The following error appears:

class file has wrong version 51.0, should be 48.0

It seems that the compiling is done on another JDK (other than 8). Can anyone please help me solve this problem?

Kindest Regards!

asked May 2, 2017 at 18:55
5
  • And what happens when you run javac --version? When you run java --version you're only showing the version of the JRE, not the JDK... Commented May 2, 2017 at 18:57
  • Similar question stackoverflow.com/questions/3535722/… Commented May 2, 2017 at 19:01
  • I tried javac -version and the following appears javac: invalid flag: -version Commented May 2, 2017 at 19:03
  • javac **--**version Commented May 2, 2017 at 20:53
  • I tried both and none of them works, do anyone have an idea why it doesn't work? putting in mind that when using java -version it works fine. Commented May 4, 2017 at 8:50

1 Answer 1

1

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.

J2SE 8=52,
J2SE 7=51,
J2SE 6.0=50,
J2SE 5.0=49,
JDK 1.4=48,
JDK 1.3=47,
JDK 1.2=46,
JDK 1.1=45

First Rule: Java version must be same on your local pc and server. Otherwise this kind of unwanted problem may arise.

For more checking, You can check

java --version

javac --version

It will make clarify of jdk and jre version mismatch. If it shows various version, then uninstall other versions and build your project and deploy on server.

Another answer is similar to your problem is here: Cannot compile Java code - "class file has wrong version 52.0, should be 48.0"

Resource Link:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/crunchify/Main : Unsupported major.minor version 51.0

answered Oct 11, 2017 at 15:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.