Hugo
Hugo

Reputation: 3

ClassNotFoundException in jar

I have a problem with a Java application. Sometimes, when I run my application on an Ubuntu Server, a ClassNotFoundException occurs. I said sometimes because the error appears randomly: sometimes after a long time (and restarting the app fixes the bug), sometimes at the first time the concerned class is used (and rebuild the app fixes the bug).

Note that it's not always the same class that causes the error. Also note that I don't use Class.forName() or Classloader.loadClass() or ClassLoader.findSystemClass().

I run my application via the command : java -jar server.jar

All the classes are in the Jar file (I unzipped it to check) and the Manifest is correct.

This is the error I get :

java.lang.ClassNotFoundException: com.edioromeh.server.server2server.S2SDroppedItem at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:266) at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:622) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1593) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at com.edioromeh.ub.server.Messenger.run(Messenger.java:44) at java.lang.Thread.run(Thread.java:722)

My java version is : java version "1.7.0_15" OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1) OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

Thanks for your help!

Upvotes: 0

Views: 749

Answers (1)

jiacheo
jiacheo

Reputation: 308

Note that when you deserialize an object by ObjectInputStream from byte array, your application must have depend on the object's class, because 'ObjectInputStream.resolveClass' method would call java.lang.Class.forName0() to make the stream become an object.

Here your application did not depend on the class named 'com.edioromeh.server.server2server.S2SDroppedItem'

You can find the .jar file which contains this class and put it into your application's classpath.

Upvotes: 1

Related Questions