0

Just to check if it runs I tried to run my Java8 compiled application with the current Oracle JDK9 (9.0.1). When starting up guice gets a ClassNotFoundExceptionf for javax.annotation.PreDestroy which is contained in a jar on the classpath. I'm using the JSR-250 extensions: http://code.mycila.com/guice/

In Java8 it runs as usual. So I'm wondering why the JDK 9 is not backwards compatible just for the runtime environment. Have I missed something to get it to work? Or do I have to configure the module path and compile my application in Java9 to get it running with the Java9 runtime?

Here is the stack trace: (full part is here: https://pastebin.ca/3894786)

c.g.i.Guice An exception was caught and reported. Message: java.lang.ClassNotFoundException: javax.annotation.PreDestroy java.lang.TypeNotPresentException: Type javax.annotation.PreDestroy not present

at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(Unknown Source)

Sorontur
  • 500
  • 4
  • 15
  • Generally speaking, you do not have to recompile or use the module path. Just putting it on a JVM 9 class path should work. Are you sure that the class path contains `PreDestroy`? Because it looks like it doesn't and you've been relying on the JDK package `javax.annotation`. The module containing it [is no longer resolved by default](https://blog.codefx.org/java/java-9-migration-guide/#Dependencies-On-Java-EE-Modules). – Nicolai Parlog Oct 24 '17 at 08:39
  • @nullpointer: thanks for the link it seems that this is the issue. so it is not backwards compatible in that case. – Sorontur Oct 24 '17 at 08:42
  • Related to [Spring: @Resource injection stopped working under JDK9](https://stackoverflow.com/questions/46494522/spring-resource-injection-stopped-working-under-jdk9/46495550#46495550) and do take a look at (2) in the [other answer](https://stackoverflow.com/a/46501720/1746118) ? – Naman Oct 24 '17 at 08:44

1 Answers1

1

Try running your application with the following VM flag:

--add-modules java.xml.ws.annotation
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
  • 1
    java.xml.ws.annotation is a subset of the annotations that were defined for JAX-WS use. Better to add the java.annotation module to the module path, or just add its artifact to the class path. – Alan Bateman Oct 24 '17 at 10:30