Edited at

Java9でeclipseを動かそうとしたらNoClassDefFoundErrorでこけた時の対処

More than 1 year has passed since last update.

デスクトップのHDDをSSDに交換したので環境構築をしていた。

せっかくJava9が正式リリースされたし、Java9+eclipse4.7で環境を作ろうと思ったら起動時にこけた。


2017/12/5追記:

https://wiki.eclipse.org/Configure_Eclipse_for_Java_9


Users who install Eclipse Oxygen 4.7.1a are able to launch with Java 9 and get Java 9 support, and the configuration described below won't be necessary anymore. There might be cases which won't work, see item 3 below in that case.


とのことなので、eclipse4.7.1a以降をインストールしよう


2017/09/27追記:

https://wiki.eclipse.org/Configure_Eclipse_for_Java_9

--add-modules=ALL-SYSTEMを追加しろって書いてあった。

(2017/10/02)問題なく動いたので修正しました。


TL;DR

eclipse.iniの-vmargsに--add-modules=ALL-SYSTEMを追加する。


eclipse.ini

-vmargs

--add-modules=ALL-SYSTEM


環境

OS: Windows8.1 64bit

JDK: Java SE Development Kit 9

eclipse: Oxygen Release (4.7.0)


やったこと


JDKのインストール

-> デフォルトのまま

> java -version

java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)


eclipseのインストール

-> eclipse.iniに-vmでjdkのパスを設定


eclipse.ini

-vm

C:\Program Files\Java\jdk-9\bin\javaw.exe


ワークスペースを作って起動

-> エラーが出てこけた


.log

!SESSION 2017-09-24 20:47:30.135 -----------------------------------------------

eclipse.buildId=4.7.0.I20170612-0950
java.version=9
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=ja_JP
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

!ENTRY org.eclipse.osgi 4 0 2017-09-24 20:47:33.101
!MESSAGE Application error
!STACK 1
org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:410)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)

...略...

Caused by: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
... 23 more
Caused by: java.lang.ClassNotFoundException: javax.annotation.PostConstruct 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)
... 25 more

!ENTRY org.eclipse.e4.ui.workbench 4 0 2017-09-24 20:47:33.117
!MESSAGE FrameworkEvent ERROR
!STACK 0
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)

...略...

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)
... 21 more



eclipse.iniの-vmargsに--add-modules=ALL-SYSTEMを追加した


eclipse.ini

    -vmargs

-Dosgi.requiredJavaVersion=1.8
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx1024m
-Declipse.p2.max.threads=10
-Doomph.update.url=http://download.eclipse.org/oomph/updates/milestone/latest
-Doomph.redirection.index.redirection=index:/->http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/
+ --add-modules=ALL-SYSTEM

-> 起動した やったね


参考

https://wiki.eclipse.org/Configure_Eclipse_for_Java_9

https://www.eclipse.org/eclipse/news/4.6/platform.php#java-9

https://issues.jboss.org/browse/JBIDE-22417?focusedCommentId=13310535&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&_sscc=t#comment-13310535