views:

561

answers:

1

I get the ff. error in Java Console occassionally:

Exception in thread "thread applet-my.package.MyApplet-10" java.lang.NoClassDefFoundError: another/package/SomeClass
    at my.package.MyApplet.init(MyApplet.java:95)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: another.package.SomeClass
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 3 more
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.class
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more

My applet tag is as follows:

<applet codebase="../../applets" code="my.package.MyApplet" class="invisible" id="myApplet">
  <param value="value0" name="param0"/>
  ...
  <param value="valueN" name="paramN" />
  <param value="folder/myApplet__0.0.1177.jar,folder/commons-io-1.3.2__0.0.1177.jar,..." name="cache_archive"/>
  <param value="0.0.1177.0,0.0.1177.0,...," name="cache_version"/>
</applet>

It is important I stress the word "occasionally". Sometimes the applet is initialized without a hitch. This also means that, often, when the browser is restarted, the problem goes away.

I am aware of http://stackoverflow.com/questions/698890/applet-fails-to-load-class-from-jar and http://stackoverflow.com/questions/872905/applet-class-loader-cannot-find-a-class-in-the-applets-jar but I think they are not applicable to my case. SomeClass and MyApplet are in the same jar and the page is being accessed locally.

+1  A: 
Caused by: java.io.IOException: open HTTP connection failed:https://myserver/mycontext/applets/another/package/SomeClass.class

This looks like there is a connection issue with retrieving the jar file from the HTTPS server.

I don't know exactly what version of Java are you running, but you can check the reason of the defect pertaining to your problem here.

If this is not the problem, then make sure that there's enough caching for your JAR file when downloaded else it fails to launch. It's not code issue unfortunately.

UPDATE Is your class SomeClass accessing any remote server or database by any chance?

The exception clearly shows that there is an AccessControl privilege that has been denied.

at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)

Bear in mind, that applets are like Flash Objects:

  • They are both downloaded and run from the client side.

Only difference is that Applets were designed with lots of access control rules such as, it must not connect to servers hidden behind company DMZ (De-Militarized Zone), etc.

If that's the case, I suggest you find a way to retrieve your data outside applets (try servlet?)

UPDATE 2 It seems the JVM can't find the trusted certificate to match with your signed jar.

  1. Since your jar file is signed make sure that the jar file can point your trusted certificate (remember, it must be trusted).
  2. More information, check: http://faq.javaranch.com/java/HowCanAnAppletReadFilesOnTheLocalFileSystem AND http://www.developer.com/article.php/3303561
The Elite Gentleman
If it's a connection issue, shouldn't the URL in the exception message be https:// myserver/mycontext/applets/myApplet__0.0.1177.jar instead? It seems that the plug-in is looking for the class file itself in the codebase.
Chry Cheng
Check my updated post.
The Elite Gentleman
SomeClass is not accessing any remote server or database. It is, however, reading files from the local filesystem. I've wrapped that in a privileged call. I've also signed the jars.I think the Java browser plug-in is doing the privileged access.
Chry Cheng
Check my updated post: I hope this helps you.
The Elite Gentleman
Thank you for your help so far but the problem is still unsolved. The jar's cert is already permanently trusted and is in both the browser and the Java plug-in's cert stores.
Chry Cheng
Which browser, the client browser? Because it seems like the client browser can't access the trusted CERT.
The Elite Gentleman
Yes, the client browser. How can you tell that the client browser can't access the cert?
Chry Cheng
Because the app is loaded by the browser (so it resides on the client, and it's executed from client side) but the Applet can't see the CERT.
The Elite Gentleman
How can you tell that the applet can't see the cert? Where in the stack trace is this indicated?
Chry Cheng
Have you configured htts proxy setting for the applet?
The Elite Gentleman