简体   繁体   English

项目有不同的Java编译器版本时是否有任何问题?

[英]Are there any issues when projects have different Java compiler versions?

I have an Eclipse workspace with several Java projects (in Maven); 我有一个带有几个Java项目的Eclipse工作区(在Maven中); these have dependencies on each other. 这些彼此依赖。 Recently I started changing just some of the projects to target Java 1.7, and other than resolving some new warnings, nothing is different when compiling. 最近我开始改变一些项目以Java 1.7为目标,除了解决一些新的警告之外,编译时没有什么不同。

However, it feels like something might go wrong when I try to run everything. 但是,当我尝试运行一切时,感觉会出现问题。 How are class files loaded, and are there any issues, in the following situations? 在以下情况下,如何加载类文件,是否存在任何问题?

  • Is there a problem when a Java 1.6 project depends on a Java 1.7 project? Java 1.6项目依赖于Java 1.7项目时是否存在问题? Will the 1.6 VM just refuse to run any 1.7-generated bytecode, or does something weird happen in order to get it to run? 1.6 VM会拒绝运行任何1.7生成的字节码,还是会发生一些奇怪的事情以使其运行?
  • Is there a problem when the reverse happens? 反向发生时有问题吗?

When you have java 1.6 project depends on a Java 1.7 project or java 1.7 project depends on a Java 1.6 project, you should always run your program on the higher version of JVM, which is java 1.7 in this case. 当你有java 1.6项目依赖于Java 1.7项目或java 1.7项目依赖于Java 1.6项目时,你应该总是在更高版本的JVM上运行你的程序,在这种情况下是java 1.7。 In a nutshell, in most cases, class files built with the Java SE 6 compiler will run correctly in Java SE 7. But there are some exceptions. 简而言之,在大多数情况下,使用Java SE 6编译器构建的类文件将在Java SE 7中正确运​​行。但也有一些例外。 Please see Incompatibilities between Java SE 7 and Java SE 6 for a list of incompatibilities between Java 6 and Java 7. 有关Java 6和Java 7之间不兼容的列表,请参阅Java SE 7和Java SE 6之间的不兼容性。

You can build a project with JDK 1.6 that has some libraries that where generated with 1.7 您可以使用JDK 1.6构建一个项目,该项目包含一些使用1.7生成的库

HOWEVER if some of the code from the project 1.7 needs some JDK 1.7 feature (for example, it uses the new Swing combobox with generics) it won't run on a 1.6 JVM. 但是,如果项目1.7中的某些代码需要一些JDK 1.7功能(例如,它使用带有泛型的新Swing组合框),它将无法在1.6 JVM上运行。

So this is something to be very careful about, as you can run into compile time trouble (which is at least not silent) but also runtime trouble. 所以这是非常小心的事情,因为你可能会遇到编译时遇到麻烦(至少不是沉默)但也会遇到运行时问题。 If you can avoid this, it might be better for you. 如果你能避免这种情况,那对你来说可能会更好。

我也面临类似的问题,据我所知,我不认为1.6 VM可以运行任何1.7生成的字节码,但我认为反过来是可能的,因为1.7是1.6VM的升级版本。

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

相关问题 Maven:项目和插件的不同Java编译器版本 - Maven: different java compiler versions for project and plugin 为什么我在不同的Eclipse项目中得到不同的Java版本? - Why am I getting different java versions in different eclipse projects? 如何处理同一台机器上不同项目的不同JAVA版本? - how to handle different JAVA versions for different projects on the same machine? 有没有办法在 IntelliJ 中同时处理具有不同 Java 版本的多个项目? - Is there a way to simultaneously work on multiple projects with different versions of Java in IntelliJ? 为什么在使用不同版本的SonarQube时会发现不同的问题? - Why different issues are found when using different versions of SonarQube? Java / Maven:不同项目中的不同slf4j版本导致集成时出现构建错误 - Java/Maven: different slf4j versions in different projects causing build errors on integration Z3 Java 绑定和 CLI 有不同的版本 - Z3 Java Bindings and CLI have Different Versions Java 19 尝试在开关表达式中记录模式时出现编译器问题 - Java 19 compiler issues when trying record patterns in switch expressions Java项目强迫依赖者采用Java版本吗? - Java projects forcing dependents to adopt Java versions? 为什么Red Hat提供使用不同Java编译器版本编译的内部版本? - Why do Red Hat provide builds compiled with different Java compiler versions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM