简体   繁体   English

当文件存在时,java.lang.NoClassDefFoundError

[英]java.lang.NoClassDefFoundError when the file is there

I've tried to look around for postings that might help me, cant find any. 我试着四处寻找可能对我有帮助的帖子,但是找不到。

I am deploying an ear to JBoss4 server, and I started having this problem since I added a new project. 我正在为JBoss4服务器部署一个耳朵,我开始遇到这个问题,因为我添加了一个新项目。

this new project is defined as Java project in eclipse, and the EAR project has an EJB project that has the new Java project as one of the projects as its dependent upon - if deployed on JBoss locally through eclipse, there's no problem and everything goes smoothly 这个新项目在eclipse中被定义为Java项目,而EAR项目有一个EJB项目,它将新的Java项目作为其依赖的项目之一 - 如果通过eclipse本地部署在JBoss上,则没有问题,一切顺利

But when being deployed to JBoss in test environment (outside eclipse), kept getting java.lang.NoClassDefFoundError on one of the classes that are defined in the new Java project. 但是当在测试环境(eclipse之外)中部署到JBoss时,不断在新Java项目中定义的类之一上获取java.lang.NoClassDefFoundError。

I looked inside the EAR file to get to the jar (EJB project), and then inside the jar, I can see the directory structure and all the class files from the new Java project - ie. 我查看了EAR文件内部以获取jar(EJB项目),然后在jar中,我可以看到新Java项目中的目录结构和所有类文件 - 即。 The class that it complains about is right there inside the EAR->JAR and matching the exact structure that it's looking for. 它抱怨的类就在EAR-> JAR内部,并且与它正在寻找的确切结构相匹配。

I am at lost to what else I can look at. 我迷失了我能看到的其他东西。

Any pointers are greatly appreciated! 任何指针都非常感谢!

Thanks 谢谢

You often get this error if there is a mismatch in the way some of the classes were compiled. 如果某些类的编译方式不匹配,通常会出现此错误。 For example if you compiled some of the classes in a later version of the JDK without setting the java compliance level and you are running it with an earlier version. 例如,如果您在更高版本的JDK中编译了某些类而未设置Java合规性级别,并且您使用早期版本运行它。

My suggestion is to check the JDK you are running JBoss with, then check how you compiled your classes 我的建议是检查你运行JBoss的JDK,然后检查你如何编译你的类

I had a problem like that with JBoss 4: ClassNotFoundException and NoClassDefFoundError at runtime even if the code compiled well. 即使代码编译得很好,我在运行时遇到了类似JBoss 4:ClassNotFoundException和NoClassDefFoundError的问题。 It took me 4 hours to find out the cause. 我花了4个小时才找出原因。

The BuildPath of my projects were ok, the problem was actually in the ClassPath of JBoss. 我的项目的BuildPath没问题,问题实际上是在JBoss的ClassPath中。 I solved it by doing : JBoss 4.2 RunTime Server > Open launch configuration > Edit Configuration > ClassPath > adding JARs and projects to link to JBoss with "Add JARs" / "Add Projects". 我解决了这个问题:JBoss 4.2运行时服务器>打开启动配置>编辑配置>类路径>添加JAR和项目以通过“添加JAR”/“添加项目”链接到JBoss。

Eclipse knew the classes in the JARs and the related projects thanks to the BuildPath, so there was no error in the IDE, but the JBoss server didn't know where to find these classes... 由于BuildPath,Eclipse知道JAR和相关项目中的类,因此IDE中没有错误,但JBoss服务器不知道在哪里找到这些类...

如果您有多个war / ear文件,这也可能是由于类加载器隔离问题

check ur ear file . 检查你的耳朵文件。 the structure like this? 像这样的结构?

myapp.ear
|+ META-INF
   |+ applications.xml and jboss-app.xml
|+ myapp.war
   |+ web pages and JSP /JSF pages
   |+ WEB-INF
      |+ web.xml, jboss-web.xml, faces-config.xml etc.
      |+ lib
         |+ tag library JARs
      |+ classes
         |+ servlets and other classes used by web pages
|+ myapp.jar
   |+ EJB3 bean classes
   |+ META-INF
      |+ ejb-jar.xml and persistence.xml
|+ lib
   |+ Library JARs for the EAR

if not , u should repackage ur ear file. 如果没有,你应该重新包装你的耳朵文件。

META-INF/MANIFEST.MF检查属性“ Class-Path :”。

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

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