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.
Judging by jnlp you haven't recreate jnlp after switching on
Unrestricted access
. Try to runClean and Build
or add next tag to your jnlp manually:I faced similar situations .. I dont know exactly which solution is what may help you .. so I will list them all :
1- be sure that the jar you are using are signed and signature is valid .. you can use jarsigner for this purposes .. because if the jars you are using are expired.. app will crash @ web. if there is a jar signed and expired . just remove all file from META-INF. ( jar is zip file btw)
2-I see your JNLP .. you need to add this attribute for the application class: main="true" so your will be :
Its important to tell app which is your application class .. I dont know why .. but I found this structure in previous version of JavaFX and it solved my problem ..
3- if you are using webPage instead of generic one .. so just check that JNLP_content serial is the same .. because each time you add/remove jars to project, the serial will be changed .consider checking URL as well .. I mean this section in HTML:
hope that is gonna help you or anyone facing the same issue ..
Good luck
Sorry guys, I did mislead you a little bit. The problem, why my application works under Netbeans and in browser not was this line in static block in my jar:
which return correct value in Netbeans (windows Xp), but Null in Browser. But when I slightly change the code to this>
it return correct value in browser too. So it has nothing to do with external jars or signing the application. The problem still remains, because that external jars is part of our corporal java infrastructure, so I just cannot change the code directly, but this would be another topic :)
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:
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"
viaSystem.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.