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 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark ""NoClassDefFound Error" deploying EAR file" Watch ""NoClassDefFound Error" deploying EAR file" New topic
Author

"NoClassDefFound Error" deploying EAR file

Amrit Kashyap
Ranch Hand

Joined: Apr 23, 2006
Posts: 44
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

Joined: Jul 20, 2005
Posts: 9962
    
163

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


[My Blog] [JavaRanch Journal]
Amrit Kashyap
Ranch Hand

Joined: Apr 23, 2006
Posts: 44
it's just typo.......

Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
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

Joined: Nov 06, 2002
Posts: 239
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.


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9962
    
163

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

Joined: Apr 23, 2006
Posts: 44
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

Joined: Aug 21, 2008
Posts: 383
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 ]
 
Consider Paul's rocket mass heater.
 
subject: "NoClassDefFound Error" deploying EAR file
 
Similar Threads
EAR Files?
Hot Deploy with Weblogic 8.1
Loading Log4j.jar from another Jar
ejb-jar / utility jar dependencies
Cannot call EJB from Servlet