1

I couldn't find an answer to this so I decided to post the question:

I have a legacy java 6 application running in Tomcat 6 currently being compiled using the latest JDK 6 (rev 45). We are about to add some Scala (2.10.3) modules (which will depend on the java ones) and I am wondering if it's worth upgrading to the JDK 7 compiler and what the possible risks are.

I am also wondering if it might be better to just bite the bullet and switch to java 7 although we might need to migrate to Tomcat 7 or other container.

Or we'll just wait for java 8!

Community
  • 1
  • 1
Giovanni Botta
  • 9,626
  • 5
  • 51
  • 94
  • 1
    *"I am wondering if it's worth upgrading to the JDK 7 compiler"* Do any of the APIs require it? If not, it is simpler to stick with Java 6. Note though, that using the right cross-compilation options, it is possible to compile code that is compatible with Java 6, using a Java 7+ compiler. – Andrew Thompson Dec 13 '13 at 15:29
  • Specifically, the `-source` and `-target` flags on the compiler. – Jesper Dec 13 '13 at 15:30
  • I think your post title is misleading. Do you want to know how to use javac v7 to compile a classfile as it was generated by javac v6 ? Or do you want opinions/advantages/disadvantages of migrating between versions? – Daniel Dec 13 '13 at 15:31
  • @DWilches changed the title to be more clear. – Giovanni Botta Dec 13 '13 at 15:36
  • @AndrewThompson that's how I feel about it in general. However some polyglot JVM languages might take advantage of the JDK7 invojedynamic to generate more efficient code but I'm not sure the advantage will be noticeable. – Giovanni Botta Dec 13 '13 at 15:38
  • possible duplicate of [Is it possible to compile class files with the Java 7 SDK which can run on Java 6 JVMs?](http://stackoverflow.com/questions/10107831/is-it-possible-to-compile-class-files-with-the-java-7-sdk-which-can-run-on-java) – Floegipoky Dec 13 '13 at 15:41
  • @Jesper Don't forget the `-Xbootclasspath` (which requires an `rt.jar` from the target version). That guarantees that the classes, attributes and methods being called, actually *existed* in the target Java version. OP: Also see the details under [Javac - cross-compilation options](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-options). – Andrew Thompson Dec 13 '13 at 15:42
  • 2
    My opinion is generally that the more you keep dependencies up to date, the less work it is to update them. The longer you wait to upgrade, the more work it takes. So I prefer to do it sooner rather than later when possible. Plus, you get all those fancy new features. – Floegipoky Dec 13 '13 at 15:44
  • @Floegipoky I agree with you. However when you have a system in production and it works fine, it's hard to find business rationale for changes that are potentially very time consuming. I would have switched to java 7 one year ago, but I wasn't working on this project back then! – Giovanni Botta Dec 13 '13 at 15:52
  • @Floegipoky also I don't think this is a duplicate question. I _know_ I can compile to target 1.6, I just would like to hear the experiences of those who did it and if it's painful to do so. – Giovanni Botta Dec 13 '13 at 15:54
  • @GiovanniBotta That is exactly the reason I'm having to hear about a co-worker trying to migrate from JBoss 4 up to 7, and I stand by my original statement :) – Floegipoky Dec 13 '13 at 15:59

1 Answers1

0

As far as generics are concerned there are some risks to compile java-6-files with a JDK-7-compiler. Some classes might not compile while some generics constructions which were not possible in Java 6 will now be compilable in a JDK-7 compiler.

So indeed there are some incompatibilities. Please study:

Oracle compatibility note

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126
  • How about polyglot JVM and Tomcat 6? What are the risks? Do they outweigh the benefits? – Giovanni Botta Dec 13 '13 at 15:37
  • Your first paragraph is pretty much what the cross-compilation options of `javac` were made for! – Andrew Thompson Dec 13 '13 at 15:44
  • yeah I have myself compiled java-6-source code with JDK-7 using the javac-options -source and -target, but really experienced compile problems. So javac cross compiling is and cannot be perfect. – Meno Hochschild Dec 13 '13 at 15:47
  • @AndrewThompson I am asking if it's _worth it_ not if it's possible. I know it's possible. I am trying to collect some experiences in doing so. – Giovanni Botta Dec 13 '13 at 15:54
  • @GiovanniBotta You could just try it out and test - first in a parallel non-production installation. Hopefully you also have a good test suite for your java-6-application. Nothing else can give you better advise than a good test. – Meno Hochschild Dec 13 '13 at 16:03