简体   繁体   中英

Java applet calling WCF Service fails with noclassdef exception at runtime

I have a java applet which uses a proxy service to a WCF Service to display data. The applet compiles and runs perfectly in Eclipse but when I build and export a Jar file then run it in a html page it fails with

java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException.

I have included jaxrpc.jar in my build path and my jar file contains all necessary classes.

The stack trace seems to be complaining about the line where I instantiate the proxy service from within the applet class. Does anyone know if there is an issue calling WCF service from a java applet?

Stack Trace:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at ListProducts.ListProducts.<init>(ListProducts.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 27 more

This has been troubling me all day.

I think your issue is loading rpc jar, not call to wcf.

This post can be helpfull: http://www.coderanch.com/t/259357/Applets/java/Applet-Axis-Client-Errors

It recomemds to sign your jar, verify you can access all your jars via browser, ensure you have all dependent.jars.

If all this will not help - i'd try to solve it as " NoClassDefFoundError from spplet" issue.

Ok. I got this working by doing several things:

First I had to sign several of the jar files I was using:

jaxrpc.jar

axis.jar

commons-discovery-0.2.jar

but not:

javax.wsdl_1.6.2.v201012040545.jar

org.apache.commons.logging_1.0.4.v201101211617.jar

Secondly - all these files had to exist in the same directory as the html page, as I didn't specify a directory in codebase property for the applet tag.

Thirdly, within my main applet (ListProducts.class) I had to use AccessController.doPrivileged() around the code that first calls the proxy service: EDIT: This step may not be necessary, as it now seems to work when I remove the doPrivileged block.

AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {

    try {

        //instantiate proxy service and make rpc's
        //do other stuff with results...


    } catch (RemoteException e) {
        // catch error
    }           


        return null;
        }
    });

This combination of things got the java applet doing what it should. It was a painful slow process to discover which jar files were missing and then signing the appropriate ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM