*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant NoClassDefFoundError" Watch "Ant NoClassDefFoundError" New topic
Author

Ant NoClassDefFoundError

Ben Rainville
Greenhorn

Joined: Dec 22, 2004
Posts: 8
Hi everyone,

I work on a struts application that runs on Jboss, and I am having a problem that I believe is due to my build.xml. I am a bit of an Ant newbie, so please bear with me.

Basically, I wanted to the jakarta commons-httpClient jar to my application, and for some reason, whenever I create an instance of the class that imports the PostMethod class (which is inside the jar) I get a NoClassDefFoundError. It's my guess that somehow the jar is not making it into the ear.

Attached is my build.xml. It's kind of large (I didn't write it -- I'm just modifying it) but the part that I think pertains to this problem is the <path id="shared.classpath"> tag. As far I can tell, it should be copying everything from the lib directory that matches commons-*.jar, and the jar in question is /lib/commons-httpClient-3.0-rc1.jar

Any ideas why I might be getting this error?

Thanks in advance,


Ben Rainville

Here's the build.xml (I couldn't figure out how to post it in here -- something about illegal HTML tags? If anyone can tell me, I'll post the xml here instead of an external link).
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Your hypothesis is that a certain jar isn't in the ear.

So, open it up and see if it is or not(use jar or winzip or your favorite tool).

If it isn't, then is it in the directory that the ear is created from? Looks like it is creating the ear from basedir -> ${dist.dir}/ear. It looks like it is including everything in that directory. Is it?


[ March 29, 2005: Message edited by: Carol Enderlin ]
Ben Rainville
Greenhorn

Joined: Dec 22, 2004
Posts: 8
Oh, good idea. Not sure why I didn't think of that myself. I looked in the ear, and the jar I want is in there. So my guess was wrong.

Any ideas what else could be the problem? What else could cause a ClassDefNotFoundError?
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Well, there are different ways to configure and package an ear to get the classpath to work.

What part of your application needs the jar you're having the trouble with? Just the web application? (you mentioned struts so I'm guessing it could be just the web app) You could put the jar in WEB-INF/lib within the war. Looks like your jar is being excluded from the war, included in the ear.

If you need those classes in multiple modules such as a war and ejb...one way is to add jars to the classpath of war and ejb.jar files is to list them in the manifest (META-INF/manifest.mf). Your build file isn't having ant create the manifests, but it does look like it could be including manifest files. You could take a look at one or two of yours from a war/ejb.jar. The manifest may have a line that starts like this "Class-Path: "

WebLogic has a feature where you can put jars into a certain location within the ear and they are available to the entire application without mucking with the manifest. Not being familiar with JBoss, I don't know what tricks it might use.

You can add jars external to the ear to the classpath used to start your server, that can be a bit tricky depending upon what the start scripts are like. I prefer to get it all working in one package (ear).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant NoClassDefFoundError
 
Similar Threads
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError..
NoClassDefFoundError