Java SE 8: Would a Java 7 compiled JAR be compatible completely with Java 8?

与世无争的帅哥 提交于 2019-12-02 12:35:31

问题


I compiled my old JAR files in Java 7 and my production environment has Java 8. Is there anything I need to be careful about directly deploying the JAR files onto Java 8 Environment? I test ran them on Java 8 and it worked fine. Could I encounter any problems or should I be fine? I was wondering this because I was debating removing Java 8 and installing Java 7.

EDIT: A side question: Do companies update their code when they update their Java version? I can't imagine how painful this must be so have your app working on a previous version and then completely fail on the new version.


回答1:


I was wondering this because I was debating removing Java 8 and installing Java 7.

I assume you mean the other way around?

Java attempts to maintain backwards compatibility as far as it can, so theoretically at least you should be ok.

In practice however, issues do sometimes come up, so I'd advocate testing thoroughly. These may be due to regression bugs, or (more likely in my experience) buggy code that might have run fine under Java 7, but not under 8. (FWIW, I had a couple of FX apps that mixbehaved under 8 but ran fine under 7, it turned out both were due to bugs in my code that coincidentally had no unusual side effects when running with 7.)




回答2:


Usually, there should be no problem. Otherwise you would have a hard time to use any third-party libraries not explicitly compiled for Java SE 8.

I recommend to run your automated tests on a continuous integration server such as Jenkins using Java SE 8 and see if you have any issues.




回答3:


It is safe to package Java 8 application with jar dependencies compiled with Java 7. Given that said, however, keep in mind differences in JDK 7 and 8, that can result the same Java code could behave differently when running on JDK 8 vs JDK 7 (refer to JDK 8 release notes)



来源:https://stackoverflow.com/questions/24615534/java-se-8-would-a-java-7-compiled-jar-be-compatible-completely-with-java-8

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