Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an Eclipse workspace with several Java projects (in 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.

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? 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?
  • Is there a problem when the reverse happens?
like image 201
Andrew Mao Avatar asked Dec 03 '25 02:12

Andrew Mao


2 Answers

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. 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. Please see Incompatibilities between Java SE 7 and Java SE 6 for a list of incompatibilities between Java 6 and Java 7.

like image 53
Lan Avatar answered Dec 04 '25 18:12

Lan


You can build a project with JDK 1.6 that has some libraries that where generated with 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.

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.

like image 39
Samuel EUSTACHI Avatar answered Dec 04 '25 17:12

Samuel EUSTACHI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!