0

I'm attempting to migrate a Maven application to Java 11 (OpenJDK 11).

To start, I am looking to compile my Java 8 project utilizing Java 11 via the release compiler option to target 8.

The compilation works fine, however when running my JUnit tests, the tests fail with various issues (Maven MyBatis tests fail when running Java 8 project compiled with Java 11).

In an attempt to eliminate variables, I've simplified the process and compiled the application with the Java 8 compiler (vs. Java 11, targeting Java 8) and then ran my tests with the Java 11 runtime - I'm still experiencing exceptions.

My understanding is that you should be able to run Java 8 applications with Java 11 as it should be backwards compatible.

What am I missing?

Ryan Griffith
  • 1,591
  • 17
  • 41
  • 3
    What exceptions are you getting? – Mureinik Sep 23 '21 at 15:07
  • 2
    Access to internal classes sometimes goes away--backwards compatibility is limited to "public" APIs. Any time byte code is mucked around with or introspected, particularly when using internal APIs, there's a risk for future deprecation. You're still *running* it on 11. – Dave Newton Sep 23 '21 at 15:13
  • 2
    Your assumptions of full backwards compatibility are wrong. Some things - like JAXB - have been removed and now require explicit dependencies, and some of the internals that, for example, mocking libraries used (or abused), have been removed or are no longer accessible. You will likely need to update some dependencies to versions that have been updated for Java 11 compatibility. – Mark Rotteveel Sep 23 '21 at 15:33

1 Answers1

3

My understanding is that you should be able to run Java 8 applications with Java 11 as it should be backwards compatible. What am I missing?

This is incorrect. Java merely promises not to break compatibility lightly. They've been interpreting 'lightly' somewhat differently, especially in the 8 to 9 transition (which broke rather a lot, really).

There are a few fairly well known issues. Post the errors and you may get some insights. At any rate, no, there is no such guarantee: Even when compiling with --release 8. It also sounds like the thing you compile it with is completely irrelevant here - the only variable that decides whether you get errors or not, is if you run the resulting class files on JDK8 or on JDK11.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • You've hit the nail on the head that many others have missed: the "what" that is being compiled matters not. The same artifacts ran on Java 8 work, ran on Java 11, no-go. I wanted to make sure I wasn't chasing ghosts and that this is in fact a compatibility issue with the compilers. If I'm understanding correctly, I'll cut my losses and go directly to Java 11 fully vs. attempting the trial I was of running Java 8 code on Java 11. – Ryan Griffith Sep 23 '21 at 15:54
  • and I'd guess in this case especially the myBatis configuration files, which if I remember are XML files, can't be read by the application when running under Java 11 because Java 11 did away with the entire XML handling API. – jwenting Sep 23 '21 at 15:59
  • @RyanGriffith It's not a compatibility issue with the compilers--it's the *runtime* that determines what's available at runtime. What's being compiled *does* matter, because not everything that's compiled is legit on every JRE. – Dave Newton Sep 23 '21 at 15:59
  • @DaveNewton in this case the compiler would have failed as well. But I think the application was compiled under Java 8 and tried to be started under Java 11. – jwenting Sep 23 '21 at 16:00
  • @jwenting I read it as compiled under JDK 11, targeting JDK 8, and was successful; it's at runtime on 11 that it fails. – Dave Newton Sep 23 '21 at 16:03
  • @DaveNewton - My mistake. I went to edit my comment but was locked out because it had been 5 minutes. You're correct that the issue is with the runtime. The code (in my second attempt) was compiled with `Java 8`, to simplify things, and then attempted to be ran using the `Java 11` runtime. – Ryan Griffith Sep 23 '21 at 16:04
  • 1
    @jwenting What do you mean about XML? Isn't everything in the java.xml module? What was removed? – erickson Sep 23 '21 at 16:08
  • @erickson lots of stuff. Well known "my code crashes with a ClassNotFoundError when running JDK11" issue. Specifically the `javax.activation` package, `@Generated`, `@ConstructorProperties`, and that's just a small selection of stuff from `java.*`/`javax.*` that disappeared. – rzwitserloot Sep 23 '21 at 17:58
  • @erickson yes, javax.xml was removed, among other things, in Java 11. – jwenting Sep 26 '21 at 12:36