JavaFX and external JARs


Question

I am trying to deploy JavaFX application, but when I run it in browser, it looks like it cannot find the classes in external jar files.

java.lang.RuntimeException: java.lang.ExceptionInInitializerError

Caused by: java.lang.ExceptionInInitializerError
at common.bo.property.TextAttributeProp.checkLimit(TextAttributeProp.java:125)

I have common.jar in my lib folder and classpath. I also use unrestricted access in project properties. And I also know about this topic JavaFx 2.0 application referencing external jars, but it wont work for me. Everything works fine when I run it from Netbeans. But in browser it wont initialize classes in external jars. Could you please help me. Thank you

jnlp file is here

 <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="JavaFXSklad2.jnlp">
    <information>
    <title>JavaFXSklad2</title>
    <vendor>xxx</vendor>
    <description>Sample JavaFX 2.0 application.</description>
    <offline-allowed/>
    </information>
    <resources os="Windows">
    <jfx:javafx-runtime version="2.0+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
    </resources>
  <resources>
     <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
         <jar href="JavaFXSklad2.jar" size="164987" download="eager" />
         <jar href="lib/common.jar" size="965131" download="eager" />
        <jar href="lib/ifxjdbc.jar" size="705534" download="eager" />
        <jar href="lib/infra.jar" size="588915" download="eager" />
    <jar href="lib/jdawt.jar" size="726475" download="eager" />
    <jar href="lib/toplink.jar" size="1450414" download="eager" />
    <jar href="lib/weblogic.jar" size="55582010" download="eager" />
      </resources>
    <security>
      <all-permissions/>
    </security>
      <applet-desc  width="800" height="600" main-class="com.javafx.main.NoJavaFXFallback"  name="JavaFXSklad2" />
  <jfx:javafx-desc  width="800" height="600" main-class="md.MainMenu"  name="JavaFXSklad2" />
  <update check="background"/> 
    </jnlp>

Edit> Finally I realize, that the problem is caused by static block in class in jar on this line>

String osName= (String) System.getProperties().get("os.name");

I also try to sign external jars and javafx jar with the same cetrificate, but without success.

1
2
5/23/2017 10:34:18 AM

If you are using NetBeans 7.1, you need to update your NetBeans to the latest nightly version http://bits.netbeans.org/download/trunk/nightly/latest/.

Earlier versions of NetBeans have a bug packaging jar files http://netbeans.org/bugzilla/show_bug.cgi?id=205844.

You can see if your NetBeans generated package has this bug by unjarring your application's jar files and checking that it's META-INF/MANIFEST.MF file includes references to your external jar files.

It looks like the jars you are using (things like Toplink, jdbc and WebLogic) require security privileges above what you are available to an unsigned application, so you also need to request further security permissions as Sergey recommends and sign your application. To do this:

  1. Right click your project in NetBeans.
  2. Choose Build | Deployment
  3. Check Request Unrestricted Access.
  4. If you have a signing certificate from a CA, click the Edit... button next to signing certificate otherwise just accept the default NetBeans generated self-signed certificate.

Note that once you do this, users will now get Info and Alert boxes when they use your application because the application is requesting increased privileges over what a normal web page would have.


In Java, if static initialization of a class fails, the class load will fail to complete, even though the class is available and on the class path. This means that the first reference to the class will generate an ExceptionInInitializerError and subsequent references to the class will generate, an often misleading, ClassNotFoundException.

ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable. The Jar containing the class file throwing the error was found and loading of the class commenced but could not be completed because errors were experienced in it's static variables or constructor.

Suspect code would be TextAttributeProp.checkLimit(TextAttributeProp.java:125), although the root cause of your issue may be elsewhere. Check what the TextAttributeProp static code is doing, and wrap static initialization methods in try catch blocks to get more debugging info, take fallback action or ignore the static initialization error.


System.getProperties() will not return you the properties you want in an unsigned applet - it will just return null. You then try to dereference this null value in a static initializer which generates a NullPointerException and causes your class load to fail and subsequent references to the class to turn up ClassNotFoundException.

If you directly get the property "os.name" via System.getProperty("os.name") rather than getting all System properties, it works because "os.name" is not marked as security sensitive. To see which properties you can and cannot request from an Applet, refer to: http://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/properties.html. Also note that an unsigned applet cannot set any System properties.


If your application is properly signed, you should be able to get and set any System properties you want. If you cannot do this, then you can file a bug against the JavaFX browser plugin at http://javafx-jira.kenai.com. First check that you have signed your app correctly by trying to do something else which requires elevated privileges, for example, read a file from your root file system from the signed applet and ensure that the read does not fail.

3
2/7/2012 8:02:39 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon