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

邮差的信 提交于 2019-12-01 17:44:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17466882/how-can-i-use-a-library-compiled-for-java-7-in-java-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!