简体   繁体   English

Jar中的ClassNotFoundException

[英]ClassNotFoundException in jar

I have a problem with a Java application. 我的Java应用程序有问题。 Sometimes, when I run my application on an Ubuntu Server, a ClassNotFoundException occurs. 有时,当我在Ubuntu服务器上运行应用程序时,会发生ClassNotFoundException。 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(). 另请注意,我不使用Class.forName()或Classloader.loadClass()或ClassLoader.findSystemClass()。

I run my application via the command : java -jar server.jar 我通过以下命令运行应用程序:java -jar server.jar

All the classes are in the Jar file (I unzipped it to check) and the Manifest is correct. 所有类都在Jar文件中(我将其解压缩以进行检查),并且清单正确。

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) 我的Java版本是:Java版本“ 1.7.0_15” OpenJDK运行时环境(IcedTea7 2.3.7)(7u15-2.3.7-0ubuntu1〜12.04.1)OpenJDK 64位服务器VM(内部版本23.7-b01,混合模式)

Thanks for your help! 谢谢你的帮助!

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. 请注意,当通过ObjectInputStream从字节数组反序列化对象时,您的应用程序必须依赖于该对象的类,因为'ObjectInputStream.resolveClass'方法将调用java.lang.Class.forName0()以使流成为对象。

Here your application did not depend on the class named 'com.edioromeh.server.server2server.S2SDroppedItem' 在这里,您的应用程序不依赖于名为“ com.edioromeh.server.server2server.S2SDroppedItem”的类

You can find the .jar file which contains this class and put it into your application's classpath. 您可以找到包含此类的.jar文件,并将其放入应用程序的类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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