Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a library compiled for Java 7 in Java 6?

I'm working on a Java application, where I need to use a jar called myBeans.jar.

This myBeans.jar contains lots of class files, that are compiled with jdk 1.7. I don't have the source code for those class files.

And my whole application is using jdk 1.6. I can't change it's compiler to jdk 1.7. So I want my jar to be compatible with my app. And that's why I want the classes of the jar to be compiled with jdk 1.6.

Now my question is: Is there any way to compile the class files (& not java files) using jdk 1.6?

Any alternate suggestions are also welcome.

Someone recommended me to get the source code from class files using decompiler & then compile the source code with jdk 1.6. But I would prefer this solution at the last as there are lots of class files.

like image 572
RAS Avatar asked Oct 22 '22 06:10

RAS


1 Answers

This will probably not work. Java 7 has introduced language features not present in earlier versions, so if any of these have been used in the library you may not be able to recompile using JDK 6.

Also, new methods and classes are introduced with each Java revision, so if any @since 1.7 items are used in the library, they will not be present in your Java 6 environment and the build will fail.

like image 165
Duncan Jones Avatar answered Oct 31 '22 16:10

Duncan Jones