3

I had installed Spring Tool Suite(version 3.9.0). It was working properly before. After installing JDK 9, I am unable to launch Spring Tool Suite.

I could see the below in the error log though :

java.lang.NoClassDefFoundError: javax/annotation/PreDestroy at org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:450) at org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:156) at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:78) at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111) at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:74) at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:178) at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:99) at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:141) at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213) at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120) at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112) at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168) at org.eclipse.osgi.container.Module.publishEvent(Module.java:476) at org.eclipse.osgi.container.Module.doStop(Module.java:634) at org.eclipse.osgi.container.Module.stop(Module.java:498) at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:202) at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:165) at java.base/java.lang.Thread.run(Thread.java:844) Caused by: java.lang.ClassNotFoundException: javax.annotation.PreDestroy cannot be found by org.eclipse.e4.core.di_1.6.100.v20170421-1418 at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)

Is the problem really because of JDK 9 ? Please point me in the right direction to resolve the issue.

Thanks.

VedantK
  • 9,728
  • 7
  • 66
  • 71
Abhi.P
  • 60
  • 8
  • [This answer](https://stackoverflow.com/a/46515247/1746118) I made recently might help you understand the cause of the failure. Though the frameworks might be different yet the cause is same. – Naman Oct 06 '17 at 06:59
  • 2
    Hi All, I have resolved the issue by myself. Have referred to the Eclipse Forum on how to configure Eclipse for JDK9. Had to add the following vmargs in the STS.ini (or eclipse.ini for Eclipse) : **--add-modules=ALL-SYSTEM** After adding the STS.ini or eclipse.ini file will look as shown below : -vmargs -Dosgi.requiredJavaVersion=1.8 --add-modules=ALL-SYSTEM Please have a look into the [link][1] for more info. Thanks. [1]: https://wiki.eclipse.org/Configure_Eclipse_for_Java_9#Configure_Eclipse_for_Java_9_modules – Abhi.P Oct 06 '17 at 08:14

2 Answers2

5

Yes, this is due to Java 9. There will probably be a bug fix in Eclipse (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=525583) but for now you can use a workaround: add --add-modules=ALL-SYSTEM to the launch configuration in eclipse.ini. For a complete example see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493761.

ewramner
  • 5,810
  • 2
  • 17
  • 33
2

In Java 9, the javax.annotation package is in a module that is not visible by default in a Java 9 runtime. The workaround is indeed to tell the Java runtime to load that module explicitly.

This means that many platforms might have to update their launch configuration if they want to run on top of the Java 9 runtime. Or, they will have to "modularize" their code and import the javax.annotation package in their modules.

Stéphane Appercel
  • 1,427
  • 2
  • 13
  • 21