如何为以前的 Java 版本构建 jar? [英] How can I build a jar for a previous Java version?

查看:35
本文介绍了如何为以前的 Java 版本构建 jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译我的代码并在不同的服务器上运行它.问题是我的 JRE 版本是 Java 版本1.6.0_13",而服务器上的版本是 Java 版本1.4.2".

I am trying to compile my code and run it on a different server. The problem is my JRE version is Java version "1.6.0_13" and that on the server is Java version "1.4.2".

当我尝试在服务器上运行 jar 时,这给了我无法识别的类文件版本"异常.我无法在服务器上编译我的代码,因为我必须设置各种依赖项.

This gives me "unrecognized class file version" exception when I try to run the jar on the server. I cannot compile my code on the server because of various dependencies I will have to set up.

所以我需要知道是否有一种方法可以使用 Eclipse"[这比命令行更容易,因为它负责处理依赖关系]并使用 1.4.2 而不是 1.6.0_13 编译我的东西.我是否必须从我的机器上卸载我的 JRE,然后重新安装以前的版本然后编译,或者有没有一种优雅和干净的方式?

So I need to know if there is a way to "use Eclipse" [this is easier than command line since it takes care of dependencies] and compile my stuff using 1.4.2 instead 1.6.0_13. Do I have to uninstall my JRE from my machine, then reinstall previous version and then compile or is there an elegant and cleaner way?

推荐答案

你应该在你的机器上安装 1.4.2 和 1.6,并将该 eclipse 项目配置为使用 1.4.2 JDK.其他项目可以配置为使用 1.6.

You should install 1.4.2 along side 1.6 on your machine, and configure that eclipse project to use the 1.4.2 JDK. Other projects may be configured to use the 1.6.

从技术上讲,您可以编译为与 JDK 1.6 兼容的 1.4.2,但很可能会遇到库问题,因此通常不值得这样做.

Technically you can compile to 1.4.2 compatibility with JDK 1.6, but odds are you will run into library problems, so it is not generally worth doing.

这篇关于如何为以前的 Java 版本构建 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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