Java applet calling WCF Service fails with noclassdef exception at runtime - java

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.

Related

Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1ObjectIdentifier

I created applet and using bouncycastle class for digital certificate.
I have make some changes for java 8 101 and sign this jar
but after changing it will throws below exception.
StackTrace :
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1ObjectIdentifier
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: org/bouncycastle/asn1/ASN1ObjectIdentifier
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
... 24 more
please help me to resolved this.
Resolved
Thanks to all
I have tried many thing but didn't find any solution.At last i tried below and its worked.
I made following changes and its work for me.
Added new jar file version is bcprov-ext-jdk15on-1.47.jar in lib folder and make entry for this jar file in MANIFEST.MF
After made changes in MANIFEST.MF i have signed both bcprov-ext-jdk15on-1.47.jar and applet.jar file and its work for me.
Thanks.
What version of bouncy castle are you using? Did you try with latest one? Please also check if your jdk is 32 bit or 64 bit. Hope this helps.

Exporting Java project as runnable Jar: not doing anything

So I have a problem with exporting my eclipse project.
The project works perfectly when running it inside eclipse, but when exporting it, it doesn't do anything.
I can't post a third link since I have less than 10 reputation, but in there I chose my "main" as launch configuration, and "package required libraries.
When I double click the runnable Jar nothing happens, nothing pops up.. No message nothing.
When I run it using java -jar smergy.jar I receive
`C:\Users\Jean>java -jar Smergy.jar
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at smergy.SmergyMain.<init>(SmergyMain.java:162)
at smergy.SmergyMain$1.run(SmergyMain.java:50)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(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$JavaSecurityAccessImpl.doIntersectionP
rivilege(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)`
Most likely the images are not being packaged into the jar. Or they are not being loaded.
One way to deal with loading resources is using the Toolkit like this:
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/package1/package2/dump.jpg")));

com.toedter.calendar.jdatechooser error when running setup created using launch4j

iam using launch4j to create a .exe file, i created runnable jar file using the export option in the file menu in eclipse.the jar file runs succesfully but whenever i create a setup file in launch4j,the setup is created successfully but when it is run i get the errors in launch4j log
Executing: E:\app.exe
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/toedter/calendar/JDateChooser
at run$1.run(run.java:9)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(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.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: com.toedter.calendar.JDateChooser
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
See the exception:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/toedter/calendar/JDateChooser
at run$1.run(run.java:9)
Whenever your class is not available for the class Loader (ie your .class file) then we will get this exception.
Read the below post for better understanding:
How to solve java.lang.NoClassDefFoundError?

Error java.lang.NullPointerException on a executable

I have created a java application to connect to a MySQL database.
Once through the program install creator I created an .exe .
This executable runs, and the first form is login. When he tries to access the database to confirm the details of login gives this error.
java.lang.NullPointerException
Someone can help me solve this? The path is correct, because if run the .jar the application runs normally.
I apologize for the inconvenience.
Only have this to try explain better my question :S
I'm so sorry... I'm running a executable version from my java aplication.
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at sensores.forms.jTMainMenu.initComponents(jTMainMenu.java:786)
at sensores.forms.jTMainMenu.<init>(jTMainMenu.java:57)
at sensores.forms.jTLoginConsulta.jBLoginActionPerformed(jTLoginConsulta.java:351)
at sensores.forms.jTLoginConsulta.access$000(jTLoginConsulta.java:59)
at sensores.forms.jTLoginConsulta$1.actionPerformed(jTLoginConsulta.java:110)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(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)
You have an error in this class/line
jTMainMenu.java:786
Seems you tried to load a image in this point of your code, i don't know how you are generating a executable from your java code but this may be the source of the problem. Try to put this image outside of your executable/jar and use a relative path to load the image, like './my_image'.
You also have to take care if your user make a link to your executable, in this case a relative path can't resolve your problem. A simple way to solve this in java is get the source code location.
getClass().getProtectionDomain().getCodeSource().getLocation();
And use this location to find your image.
Please check the line number from the Stacktrace where you are getting the NullPointerException.
it is straight forward to find out the null pointer exception. Object is null or not initialize on which you are calling the method
try{
// add database connection statement here
}catch(Exception e){
e.printstacktrace();
}
// run the program from the command prompt.
// you can print the e.printstacktrace() on the popup as well to get the exception details
If you make a .jar, move that jar somewhere separate from the IDE (i.e. their classpaths), and start the jar, do you receive a NullPointerException?
This can be caused by resources, getResource, getResourceAsStreem, getBundle, as they are not case-sensitive in the Windows file system, but are case sensitive in a jar(and under Linux/MacOS).
(Also File cannot be used for jar resources.)
You might look in the jar with 7zip or so to inspect all paths.
I think it is not getting image icon in defined path
at javax.swing.ImageIcon.<init>(Unknown Source)
I have the following two guesses:
There is a problem with your path or classpath and loading the resource
The lines
at sensores.forms.jTMainMenu.initComponents(jTMainMenu.java:786)
at sensores.forms.jTMainMenu.(jTMainMenu.java:57)
indicate that something is initialized. Usually Swing/AWT uses multiple threads, so you might have a race condition here: The reference to the resource is handed to ImageIcon in your ìnitComponents method before another thread could set the value to something non-null. Try using proper synchronization/locking.

Runnable JAR file doesn't run after export in Eclipse

I have the following hierarchy :
When I export the project into a runnable JAR file (32 bit platform) , the file
is created successfully , but when I try to run it , nothing happens - no response from the OS (windows 7 pro) .
Why can't I run the jar file ?
Thanks
EDIT:
C:\1>java -jar ex3.jar
Catched FileNotFoundException: C:\1\ex3-natives-windows-i586.jar (The system can
not find the file specified), while TempJarCache.bootstrapNativeLib() of jar:fil
e:/C:/1/ex3-natives-windows-i586.jar!/ (file:/C:/1/ + ex3-natives-windows-i586.j
ar)
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no gluege
n-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoad
erBase.java:442)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.ja
va:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNIL
ibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.j
ava:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrar
y(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:251)
at com.jogamp.common.os.Platform.access$000(Platform.java:57)
at com.jogamp.common.os.Platform$1.run(Platform.java:186)
at com.jogamp.common.os.Platform$1.run(Platform.java:183)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:246)
at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:196)
at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:186)
at WorldController.<init>(WorldController.java:119)
at WorldController$1.run(WorldController.java:478)
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 Sour
ce)
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)
C:\1>
Updated :
C:\>
C:\>java -jar ex3.jar
Exception in thread "main" java.lang.IllegalAccessException: Class org.eclipse.j
dt.internal.jarinjarloader.JarRsrcLoader can not access a member of class WorldC
ontroller with modifiers "public static"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Sour
ce)
at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
C:\>
It seems that you got a illegal call. That means you try to call a method wich you're not allowed to call. (referenced to your updated edit)
Your error says that you want to execute a method with the modifiers public static. A static method must be calls with the class name not with the object:
SomeClass.staticMethodCall();
The following would be wrong:
SomeClass sc = new SomeClass();
sc.staticMethodCall();

Categories