java.lang.NoClassDefFoundError when the file is there
Asked Answered
I

5

9

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.

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

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.

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. The class that it complains about is right there inside the EAR->JAR and matching the exact structure that it's looking for.

I am at lost to what else I can look at.

Any pointers are greatly appreciated!

Thanks

Inaction answered 14/1, 2011 at 4:34 Comment(2)
I tried everything and it still giving me the same exceptionInaction
I forgot to reply to this thread - as an update: I found out what the problem was, which was really silly, at some point along the way, I renamed the package name by changing a character to capitalized. eg. from packagename, to packageName - and somewhere along the way, some class files still reference it by the old name (non capitalized) and hence the NoClassDefFoundErrorInaction
P
7

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.

My suggestion is to check the JDK you are running JBoss with, then check how you compiled your classes

Phenacite answered 14/1, 2011 at 5:55 Comment(1)
Funnily, the problem was because I was changing the package name with some characters capitalized to non-capitalized or vice versa and it screws up the files inside the jarInaction
V
2

I had a problem like that with JBoss 4: ClassNotFoundException and NoClassDefFoundError at runtime even if the code compiled well. It took me 4 hours to find out the cause.

The BuildPath of my projects were ok, the problem was actually in the ClassPath of JBoss. 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".

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...

Vincennes answered 21/5, 2014 at 7:19 Comment(0)
N
1

This could also be due to classloader isolation issues if you have multiple war/ear files

Negrete answered 14/1, 2011 at 7:51 Comment(0)
J
0

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.

Jacquettajacquette answered 14/1, 2011 at 4:50 Comment(1)
That's pretty much how the structure is, though in the EJB jar, I have persistence.xml instead of ejb-jar.xmlInaction
G
0

Check property "Class-Path:" in META-INF/MANIFEST.MF.

Gullah answered 14/1, 2011 at 4:54 Comment(1)
Try to write the dependency jar, like "Class-Path: dependencyA.jar dependencyB.jar"Gardy

© 2022 - 2024 — McMap. All rights reserved.