JavaFX SwingNode ExceptionInInitializerError

时间:2015-10-05 14:56:26

标签: java swing javafx

当启动JavaFX应用程序(嵌入了Swing代码)作为Webstart时,会发生以下错误:

java.lang.ExceptionInInitializerError
    at com.ookali.reol.annotator.mainApp.MainApp.start(MainApp.java:481)
    at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Error when calling sun.swing.JLightweightFrame.getMethod('notifyDisplayChanged').
    at javafx.embed.swing.SwingNode$OptionalMethod.<init>(Unknown Source)
    at javafx.embed.swing.SwingNode.<clinit>(Unknown Source)
    ... 9 more
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.swing")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPackageAccess(Unknown Source)
    at sun.plugin2.applet.SecurityManagerHelper.checkPackageAccessHelper(Unknown Source)
    at sun.plugin2.applet.FXAppletSecurityManager.checkPackageAccess(Unknown Source)
    at java.lang.Class.checkPackageAccess(Unknown Source)
    at java.lang.Class.checkMemberAccess(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    ... 11 more

MainApp.java:481上的代码

final SwingNode sNcontent = new SwingNode();

在Windows 7中使用Java 8 Update 60,Java Security Level&#34; High&#34;进行测试。应用程序的所有jar都使用有效证书进行签名。如果应用程序作为独立应用程序启动,则启动时没有任何例外。

我尝试将jnlp文件中的权限设置为all-permissions或j2ee-application-client-permissions但这种方式因为安全问题而拒绝启动应用程序。 通过rt.jar(来自jdk)添加com.sun包对此问题没有影响。

这是使用的jnlp文件:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="App.jnlp">
  <information>
    <title>Annotator</title>
    <vendor>Unknown</vendor>
    <description>pdfannotator</description>
    <offline-allowed/>
  </information>
  <resources>
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="application.jar" size="656744" download="eager" />
    <jar href="lib/chemistry-opencmis-client-api-0.13.0.jar" size="45801" download="eager" />
    <jar href="lib/chemistry-opencmis-client-bindings-0.13.0.jar" size="372941" download="eager" />
    <jar href="lib/chemistry-opencmis-client-impl-0.13.0.jar" size="168501" download="eager" />
    <jar href="lib/chemistry-opencmis-commons-api-0.13.0.jar" size="154224" download="eager" />
    <jar href="lib/chemistry-opencmis-commons-impl-0.13.0.jar" size="705465" download="eager" />
    <jar href="lib/commons-codec-1.9.jar" size="289895" download="eager" />
    <jar href="lib/commons-io-2.4.jar" size="202638" download="eager" />
    <jar href="lib/commons-logging-1.2.jar" size="70678" download="eager" />
    <jar href="lib/gson-2.2.4.jar" size="211432" download="eager" />
    <jar href="lib/httpclient-4.5.jar" size="782684" download="eager" />
    <jar href="lib/httpcore-4.4.1.jar" size="354806" download="eager" />
    <jar href="lib/jackson-annotations-2.6.0.jar" size="57828" download="eager" />
    <jar href="lib/jackson-core-2.6.0.jar" size="273338" download="eager" />
    <jar href="lib/jackson-databind-2.6.0.jar" size="1218384" download="eager" />
    <jar href="lib/json-20141113.jar" size="73899" download="eager" />
    <jar href="lib/pdfbox-app-1.8.10.jar" size="10968615" download="eager" />
    <jar href="lib/rt-1.5.0_06.jar" size="68040885" download="eager" />
    <jar href="lib/slf4j-api-1.7.5.jar" size="34205" download="eager" />
    <jar href="lib/stax2-api-3.1.4.jar" size="178711" download="eager" />
    <jar href="lib/swing-layout-1.0.3.jar" size="125697" download="eager" />
    <jar href="lib/woodstox-core-asl-4.4.0.jar" size="510465" download="eager" />
  </resources>
  <jfx:javafx-desc  width="600" height="400" main-class="com.ookali.reol.annotator.mainApp.MainApp"  name="annotator" >
  </jfx:javafx-desc>
  <update check="background"/>
</jnlp>

1 个答案:

答案 0 :(得分:0)

问题是PermissionException&#34; accessClassInPackage.sun.swing&#34;这表示在Webstart中不允许使用sun.swing包。 不得不删除sun.swing包中所有类的用法,以使其正常工作。