Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"NoClassDefFound Error" deploying EAR file

 
Amrit Kashyap
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am facing problem in deploying my ear file.

Following is the structure of my ear file

-----MyEAR.ear
--MYEJB.jar
--META-INF/Manifest.mf
--META-INF/EJB-JAR.xml
--MYWEB.war
--META-INF/Manifest.mf
--META-INF/application.xml
--log4j.1.2.9.jar

Follwoing is the content for my Manifest.mf for MYWEB.war

Manifest-Version: 1.0
Created-By: 1.4.2_06 (Sun Microsystems Inc.)

and follwoing is the content for my Manifest.mf for MYEJB.jar
Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10g 10.1.2
Class-Path: log4j-1.2.9.jar

When I try to deploy this file, i gets the following error message

error instantiating application 'MyEAR' at file:
../j2ee/home/applications/MYEAR.ear:
Error initializing ejb-module;
Exception Error loading class 'common.loginejb.LoginSessionBean': java.lang.NoClassDefFoundError: org/apache/log4j/Logger

I am using oracle10g AS for deploying my ear file.

My requirement is that I've to pack this log4j-1.2.9.jar file in the ear file itself. I cannot put it in applib folder or any other folder in the class-path.

Since as far as I know according to J2EE specification, if I put the class-path entry in META-INF/manifest.mf file, then EJBJAR file should pick that.

Please suggest where I am wrong.

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--log4j.1.2.9.jar

Class-Path: log4j-1.2.9.jar


Is this a typo in your post or is this how the classpath is set? If the jar file name is log4j.1.2.9.jar then it should be the same in the Class-Path too (i.e. should not contain the - )
 
Amrit Kashyap
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's just typo.......

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't external jars be places in a lib directory within the EAR? You can override it in application.xml, but this is the default.
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to have this log4j jar in the APP-INF\lib folder of the ear archive for your requirement.

You don't have to specify anything in the manifest.mf file.

To get a hang on this, please read the j2ee classloaders functioning.

for e.g. When a class in war archive gets loaded, the web classloader starts locating other depending class files. The search is delegated to the parent i.e. ear class loader. This ear class loader delegates to the system classloader and the system classloader delegates to the bootstrap class loader.

The bootstrap classloader tries to find the requested class definition in the java/ext/lib or in the bootstrap path. If it is unsuccessfull then the request is handled by the system classloader which hunts for the class in the system classpath variable. If this also fails, the request is handled by the ear classloader, which looks for the class in the APP-INF/lib. If this also fails, the web classloader looks into the web-inf/lib folder.

If it is not found anywhere, you get NoClassDefFoundError.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajah Nagur:
You have to have this log4j jar in the APP-INF\lib folder of the ear archive for your requirement.


The APP-INF folder is specific to some server (not sure which) and is not a standard.

As suggested by Raf, the common jars go in the lib folder of the EAR:

Shouldn't external jars be places in a lib directory within the EAR? You can override it in application.xml, but this is the default.
 
Amrit Kashyap
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi raf,

the log4j jar file is being used by both my web and ejb archieve.

can you tell me where should i put the log4j jar file.

since putting in web-inf/lib does not work...........
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, you should not put it in WEB-INF/lib. You do it in your EAR/lib directory, so that the structure is similar to this:


So, the lib directory that contains the shared jars should be put on the same level as you put the modules. Note, that you may change the default "lib" directory using the <library-directory> element, which is a child of the <application> element in application.xml file.
This is the standard JavaEE way to include shared libraries.
Cheers.
[ December 10, 2008: Message edited by: Raf Szczypiorski ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic