简体   繁体   中英

Does javac -target 1.3 guarantee that the classes will run under JRE 1.3?

The article " Don't be fooled by javac -target 1.4 " shows that compiling with -target 1.4 still can create class files which will not run on JRE 1.4.

It also describes how the -bootclasspath parameter can solve this problem.

Now my question: if I compile with the Sun JDK 1.6 version of javac, using the source and target parameters set to 1.3, is safe to assume that the compiled classes will work on a JRE 1.3?

如果您使用标准库中1.3中不存在的任何方法或类,它们将无法工作,因为这些文件未编译到您的程序中,但它们是JVM库的一部分。

In fact, like the article says, your code will be bytecode compatible with 1.3, but not linkable with 1.3. As a consequence, it is possible for you to use post 1.3 classes or method (as states their example) as long as you use a rt.jar coming from a version more recent than the expected 1.3.

As a consequence, the only sure way to develop for 1.3 is to use a 1.3 JDK ... or to rely on verification tools, like ... oh crap ! i'm sure there is one maven reporting plugin that can check your code is compatible with expected JDK, but can't find back how it's named.

However, notice there exist tools like Retrotranslator , that will take your post 1.5 code to adapt it to previous versions ... as long as your code solely relys on JDK, as they may not be able to handle all external APIs dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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