Rohit Shekhar
Rohit Shekhar

Reputation: 315

How to link code that is compatible with other version of java

My existing server is running on Java 1.6 and I cant upgrade it.

I need to use some third party jar/api that is compatible with Java 1.8, when I write some code to access its API, eclipse throws

Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version

How I can proceed now? Not sure if this is duplicate question, if yes please provide some link on this.

Upvotes: 2

Views: 195

Answers (5)

DwB
DwB

Reputation: 38328

If you must use this 3rd party jar, then you must compile the 3rd party jar using -target 1.6 (to target java 1.6). Maybe you will get the source and compile it yourself or maybe you will get somebody else (the vendor, perhaps) to compile it.

All other options are:

  1. Upgrade your JVM to Java 8.
  2. Don't use that 3rd party jar. Either write or find one that is compatible with java 6.

Upvotes: 0

GhostCat
GhostCat

Reputation: 140613

The point is: Java virtual machines are not forward compatible.

A .class file that was generated by an "n+1" compiler can't be used on a "n" JVM. (unless you specifically instruct the compiler to compile for older versions of java)

Your choices:

  • see if you can acquire a version of that library compiled for Java 6
  • see if you can run your application on a Java 8 JRE (there is no problem running java6 classes on a newer JVM!)

Option 1 can get pretty ugly - as that library might have dependencies on system classes that Java6 doesn't have.

Upvotes: 2

Youcef LAIDANI
Youcef LAIDANI

Reputation: 60046

This is not possible to use multiples Java version or even multiples JVMs in the same project

If you really need this API, then you have just few choices, the best one is to upgrade all the project to use Java 1.8

Upvotes: 1

nasukkin
nasukkin

Reputation: 2540

As others have pointed out, you can't do this. However, you may be able to find older versions of the libraries you wish to use, and those libraries may support your particular version of Java. This potentially means that you will be adopting bugs into your software, but that's just how software evolves over time.

Upvotes: 0

stefan bachert
stefan bachert

Reputation: 9624

No, you can't use jars compiled under java 1.8 in an environment running at java 1.6

Upvotes: 0

Related Questions