如何使用Java 6中为Java 7编译的库? [英] How can I use a library compiled for Java 7 in Java 6?

查看:253
本文介绍了如何使用Java 6中为Java 7编译的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Java应用程序,我需要使用一个名为 myBeans.jar 的jar。

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

myBeans.jar 包含许多使用 jdk 1.7 编译的类文件。我没有这些类文件的源代码。

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.

我的整个应用程序使用 jdk 1.6 。我无法将其编译器更改为 jdk 1.7
所以我想让我的jar与我的应用程序兼容。这就是为什么我想使用 jdk 1.6 编译jar的类。

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.

现在我的问题是:使用jdk 1.6编译类文件(& not java文件)的方法?

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.

有人推荐我使用反编译器从类文件中获取源代码。然后用jdk 1.6编译源代码。但我更喜欢这个解决方案,因为有很多类文件。

Someone recommend 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 the last as there are lots of class files.

推荐答案

这可能不工作。 Java 7引入了早期版本中不存在的语言特性,因此如果在库中使用了这些特性,您可能无法使用JDK 6重新编译。

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.

,每个Java版本都引入了新的方法和类,因此如果在库中使用了 @since 1.7 项,它们将不会出现在Java 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.

这篇关于如何使用Java 6中为Java 7编译的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆