简体   繁体   English

如何防止Java 1.4项目使用1.5 / 1.6特定的API?

[英]How can I prevent a java 1.4 project from using 1.5/1.6 specific API?

Is there any way to restrict a java project configured with 1.4 compiler compliance level from using 1.5/1.6 specific API where the system is playing with 1.6 JRE? 有什么方法可以限制配置有1.4编译器遵从性级别的Java项目使用1.5 / 1.6特定的API(系统正在使用1.6 JRE来运行)?

Setting only 1.4 compiler compliance level on my project does not warn me from using especially 1.5/1.6 specific java.lang.String methods. 在我的项目上仅设置1.4编译器符合性级别并不会警告我不要使用特别是1.5 / 1.6特定的java.lang.String方法。

Make sure that you're also using an 1.4 JRE system library in your project. 确保在项目中也使用1.4 JRE系统库。 The 1.4 compiler settings change the features which will be written into the class files, it doesn't restrict what you can see from the libraries in your project. 1.4编译器设置更改了将写入类文件的功能,但并不限制您从项目库中看到的内容。

Open the properties for your project and check what you find under "Java Build Path" -> "Libraries" -> "JRE System Library". 打开项目的属性,然后检查在“ Java Build Path”->“ Libraries”->“ JRE System Library”下找到的内容。 Click "Edit" to change or add new Java versions. 单击“编辑”以更改或添加新的Java版本。

我建议最安全(也许也是最简单)的方法是使用JDK 1.4进行编译 ,然后使用JRE 1.6进行运行

You will need the rt.jar from a 1.4 JRE (for instance by having the 1.4 JRE installed). 您将需要1.4 JRE中的rt.jar (例如,通过安装1.4 JRE)。 If using javac use the following options: 如果使用javac使用以下选项:

 javac -source 1.4 -target 1.4 -bootclasspath /path/to/j2se1.4/lib/rt.jar [...]

Using javac from a later JRE means that it should have fewer bugs for old source, although it may not necessarily be entirely "bug compatible". 从更高版本的JRE使用javac意味着它对旧源代码的错误应较少,尽管不一定完全与“错误兼容”。

You might also want to use -Djava.ext.dirs=directories and -Djava.endorsed.dirs , but putting things in those directories is generally a bad idea. 您可能还想使用-Djava.ext.dirs=directories-Djava.endorsed.dirs ,但是将内容放在这些目录中通常是一个坏主意。

Note: Even 1.5 has finished its End Of Service Life period. 注意:甚至1.5版都已结束其使用寿命。 Get with 1.6! 获得1.6! (Or buy one of our excellent Java for Business contracts...) (或购买我们出色的Java for Business合同之一...)

What I would do is to remove those JDKs/JREs, which you don't want to use, from Eclipse's settings. 我要做的是从Eclipse的设置中删除那些您不想使用的JDK / JRE。 In your case that would be 1.5 and 1.6. 您的情况将是1.5和1.6。

To do this, go to Windows->Preferences and then type "JRE" in the top left hand side. 为此,请转到Windows->首选项,然后在左上角键入“ JRE”。

I would also check which JRE Eclipse in launched in and maybe edit your eclipse.ini. 我还将检查启动了哪个JRE Eclipse,也许还要编辑您的eclipse.ini。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM