File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Getting java.lang.NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Getting java.lang.NoClassDefFoundError" Watch "Getting java.lang.NoClassDefFoundError" New topic
Author

Getting java.lang.NoClassDefFoundError

Balaji Narasimhulu
Greenhorn

Joined: Oct 04, 2005
Posts: 4
Hi All,

We have a scenario in our application that, we have a JAR and WAR file. The JAR contains an MDB. WAR contains a web application. The deployment is on Websphere Application Server. Few of the common classes are required to be present in both the JAR and WAR files. When the JAR and WAR files were packaged as an EAR, the JAR file was getting loaded first, and therefore when the server was loading the WAR file, we encountered problems during loading the common classes by the Class Loader.

Thus, we are currently deploying JAR and WAR files separately. Deployment has been successful. But, now the problem is that when the MDB is getting invoked, we are encountering java.lang.NoClassDefFoundError within the execution of the JAR file, even though the class file is present in the JAR file.

Any ideas or advise please to overcome this error.

Thanks,
Balaji
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30382
    
150

Balaji,
How does the WAR know about the JAR? Is it in the classpath?

Also, why not just put the jar in the WAR's WEB-INF/lib directory? Then it can be deployed as one unit.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Balaji Narasimhulu
Greenhorn

Joined: Oct 04, 2005
Posts: 4
Jeanne,

The WAR doesnt required to know about the JAR file. The WAR file puts a message on the queue. The JAR contains an MDB which listens to the queue and starts processing the message put by the WAR file.

The JAR cant be put inside WAR's WEB-INF/lib as it needs to be deployed for processing the message.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
What are the common classes you said are required for both ear and jar? I will suggest you dont duplicate them in both the applications but rather create a Shared library in Websphere and link both these applications to this shared library.

Are you getting a java.lang.NoClassDefFoundError for one of those common classes?
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189

Move your common classes into a new java project, and make it a jar. Put that jar into class path of WAR and JAR(MDB related).
Make sure that your MDB related JAR does not depend on WAR.

As the common design principles says, WAR contains your presentaion layer, MDB JAR contains your service layer.

Presentaion layer depends on Service layer. Service layer never depend on Presentation layer.
If there are some common classes used in both the layers, they should go into a separate JAR, which is a simple java project.

Hope that clears the path issues !


SCJP 5, SCWCD 5
Balaji Narasimhulu
Greenhorn

Joined: Oct 04, 2005
Posts: 4
yes, the error is happening in the JAR file for the common classes, even though the common classes reside within the jar file.

But still, say if we avoid duplicating the common files within JAR and WAR file, instead of creating a separate JAR file as you suggested, say, we have the files within the WAR itself, can we make the code in JAR file refer to the common files within the WAR file?
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189

Ideally you should keep your common classes in the EJB module(JAR), and make your WAR depend on JAR for the common classes. Make sure your class path settings are correct.

In this case you need to deploy both the files as part of EAR. Other wise you get the classpath errors.
 
 
subject: Getting java.lang.NoClassDefFoundError