GWT:Eclipseプラグインサンプルが最新Javaで動作しない
Eclipse用のGWTプラグインで作成されるサンプルが最新のJavaでは動作しない(実際にはJava9以上では動作しない)。
つまり、File->New->Projectで以下を選択した時に自動作成されるGWTのプロジェクトサンプルだ。
実際に、Eclipseのデフォルト開発環境をJava12にしておいたら、エラーが発生して実行できない。
Javaライブラリのバージョンを変える
まずはコンソールで以下のエラーが発生する。
Running CodeServer with parameters: [-noprecompile, -port, 9876, -sourceLevel, 1.8, -bindAddress, 127.0.0.1, -launcherDir, C:\sample\war, -logLevel, INFO, -style, OBFUSCATED, sample.Sample]
Super Dev Mode starting up
workDir: C:\Users\admin\AppData\Local\Temp\gwt-codeserver-15084633959763925583.tmp
2019-07-11 11:29:23.815:INFO::main: Logging initialized @6078ms
Loading Java files in sample.Sample.
Module setup completed in 6122 ms
2019-07-11 11:29:26.549:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
2019-07-11 11:29:26.634:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@3bb47d36{/,null,AVAILABLE}
2019-07-11 11:29:26.667:INFO:oejs.ServerConnector:main: Started ServerConnector@78a884{HTTP/1.1}{127.0.0.1:9876}
2019-07-11 11:29:26.668:INFO:oejs.Server:main: Started @8932ms
The code server is ready at http://127.0.0.1:9876/
Code server started in 7.018 s ms
[ERROR] jreLeakPrevention.gcDaemonFail
java.lang.ClassNotFoundException: sun.misc.GC
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:292)
見ての通り、このバージョンのJettyではsun.misc.GCを呼び出そうとしており、Java9以上では呼び出せないのである。したがって、いずれかの方策を行う必要がある。
- Jettyのバージョンを変更する
- Javaライブラリのバージョンを変更する
前者は少々難しい。なぜなら、Jettyのjarファイルまるごとがgwt-dev-*.jarの中に組み込まれているからだ。これを置き換えねばならない。
とりあえずは、JavaライブラリのバージョンをJava8にすることで解決する。
コンパイラのバージョンを変える
上記の方策を施しても、まだエラーが発生する。
Running CodeServer with parameters: [-noprecompile, -port, 9876, -sourceLevel, 1.8, -bindAddress, 127.0.0.1, -launcherDir, C:\sample\war, -logLevel, INFO, -style, OBFUSCATED, sample.Sample]
Super Dev Mode starting up
workDir: C:\Users\admin\AppData\Local\Temp\gwt-codeserver-6065657314423861875.tmp
Loading Java files in sample.Sample.
2019-07-11 11:40:13.659:INFO::main: Logging initialized @11056ms
Module setup completed in 5778 ms
2019-07-11 11:40:15.426:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
2019-07-11 11:40:15.463:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@5ada5fd3{/,null,AVAILABLE}
The code server is ready at http://127.0.0.1:9876/
2019-07-11 11:40:15.500:INFO:oejs.ServerConnector:main: Started ServerConnector@34e4542d{HTTP/1.1}{127.0.0.1:9876}
2019-07-11 11:40:15.501:INFO:oejs.Server:main: Started @12897ms
Code server started in 6.248 s ms
2019-07-11 11:40:18.676: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@6cdea0fe{/,file:/C:/sample/war/,STARTING}{C:\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)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:447)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:479)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1337)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:550)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
とりあえず、これもJettyの問題のようだ。サーバ側のGreetingService.classをJettyがスキャンしたところ、想定より上位のJavaバージョンだったということらしい(明確にはわかっていない)。
これもまた、コンパイラのバージョンをJava8に変更する。
コンパイラバージョンを変更すると、今度は以下のエラーが発生する。
Java compiler level does not match the version of the installed Java project facet.
「.settings/org.eclipse.wst.common.project.facet.core.xml」の以下の部分を変更すればよい。
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="12"/> <!-- ここを1.8に -->
<installed facet="com.gwtplugins.gwt.facet" version="1.0"/>
</faceted-project>
ディスカッション
コメント一覧
まだ、コメントがありません