GWT2.8.2をJava9以上で動かす

2019年7月31日

※注意
以下の方法ではうまく動作しないケースがあることがわかった。引き続きまともに動作する方法を継続調査中であるので注意

Java9以上でSuper DevModeを動作させた場合に問題が発生するらしい。以下の環境で検証した。

  • Windows7 64bit
  • GWT2.8.2
  • AdoptOpenJDK12
  • Eclipse 2019-06
  • GWT plugin 3.0

発生する問題

GWTプラグインが生成するサンプルプログラムを起動したときに発生する。

2019-07-14 00:04:55.038:INFO::main: Logging initialized @2061ms
   Loading Java files in sample.Sample.
   Module setup completed in 22516 ms
2019-07-14 00:05:16.681:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
2019-07-14 00:05:16.730:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@5c243b32{/,null,AVAILABLE}
2019-07-14 00:05:16.806:INFO:oejs.ServerConnector:main: Started ServerConnector@5856ded1{HTTP/1.1}{127.0.0.1:9876}
2019-07-14 00:05:16.806:INFO:oejs.Server:main: Started @23830ms

The code server is ready at http://127.0.0.1:9876/
Code server started in 22.89 s ms
[ERROR] jreLeakPrevention.gcDaemonFail
java.lang.ClassNotFoundException: sun.misc.GC
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
(略)
2019-07-14 00:05:17.200:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
Starting Jetty on port 8888
   [WARN] Failed startup of context c.g.g.d.s.j.WebAppContextWithReload@c0762f9{/,file:/C:/devel/workspace/sample/war/,STARTING}{C:\devel\workspace\sample\war}
MultiException[java.lang.RuntimeException: Error scanning file GreetingService.class, java.lang.RuntimeException: Error scanning file GreetingServiceAsync.class, java.lang.RuntimeException: Error scanning file Sample$1.class, java.lang.RuntimeException: Error scanning file Sample$1MyHandler$1.class, java.lang.RuntimeException: Error scanning file Sample$1MyHandler.class, java.lang.RuntimeException: Error scanning file Sample.class]
    at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:536)
(略)

Caused by: MultiException[java.lang.RuntimeException: Error scanning file GreetingService.class, java.lang.RuntimeException: Error scanning file GreetingServiceAsync.class, java.lang.RuntimeException: Error scanning file Sample$1.class, java.lang.RuntimeException: Error scanning file Sample$1MyHandler$1.class, java.lang.RuntimeException: Error scanning file Sample$1MyHandler.class, java.lang.RuntimeException: Error scanning file Sample.class]
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:681)
(略)
Caused by: java.lang.RuntimeException: Error scanning file GreetingService.class
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:708)
    ... 8 more
Caused by: java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)

そしてこのままブラウザを開いても次の画面になる。Jettyが正常に起動していないがためだ。

「java.lang.ClassNotFoundException: sun.misc.GC」

これはDevModeがJava9以降で廃止された「sun.misc.GC」を参照しているがために起こるらしい.
ClassNotFoundException when running JettyLauncher with Java 9で報告されている。

回答者が言うには、特に問題は無いという。もちろんこれは、開発環境でのことなので、動作するならそれはそれで問題無い。

Jettyのエラー

次に、Jettyが起動時に以下のエラーを出している。

Starting Jetty on port 8888
   [WARN] Failed startup of context c.g.g.d.s.j.WebAppContextWithReload@c0762f9{/,file:/C:/devel/workspace/sample/war/,STARTING}{C:\devel\workspace\sample\war}
MultiException[java.lang.RuntimeException: Error scanning file GreetingService.class

明確にはわからないのだが、Jettyのバージョンが古いせいだろう。gwt-dev.jarにはJettyの特定のバージョンが組み込まれているので、簡単にはバージョンアップできない。

最新のJettyを使う方法

以下の方法で最新のJettyを使うことにする。

  • gwt-2.8.2フォルダをまるごとコピーし、gwt-2.8.2-modなどという名前にする。
  • その中にあるgwt-dev.jarを解凍し、org.eclipse.jetty以下をすべて削除し、再度jarとして構成しgwt-2.8.2-modフォルダに入れる。
  • Jettyが抜かれたこのgwt-2.8.2-modを使用する。
  • Jettyの最新バージョンを使用するために、以下をGradleの依存に入れる。
compile group: 'org.eclipse.jetty.aggregate', name: 'jetty-all', version: '9.4.19.v20190610'
compile(group: 'org.eclipse.jetty', name: 'apache-jsp', version: '9.4.19.v20190610') {
  exclude group: 'org.mortbay.jasper'
}

※上は最低限動作する大雑把な設定。不要なものも入ってしまうかもしれない。

以上でsun.misc.GCのエラーは表示されるものの、正常に動作するようになった。

org.eclipse.jettyパッケージを抜いたgwt-dev.jar(2.8.2)

以下はgwt-2.8.2/gwt-dev.jarのコピーだが、org.eclipse.jettyパッケージを削除したものだ。

gwt-dev.jar