Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting java.lang.NoClassDefFoundError

 
Balaji Narasimhulu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Balaji Narasimhulu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Balaji Narasimhulu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic