Questions on Dependencies

I have a few questions about dependencies. I've simplified the problem below considerably, so understand that I can't simply restructure everything.

I have a problem where a Web-App's MANIFEST-MF references <project1>.jar, which is contained in the EAR file.

That was fine until I added code to <project1>.jar that was dependent on <project2.jar>.

<project2>.jar exists in the Web-Apps WEB-INF/lib directory.

1) The Web App calls code in project1.jar, which calls code in project2.jar. At that point I get a classcastexception.

Why is it that it doesn't look in the WEB-INF/lib directory jars for the class? Is it because the project 1 code exists outside the WEB-INF directory?

2) I can add project2.jar to the ear and reference it in the MANIFEST.MF. If I do this, why does the class cast exception go away?

[881 byte] By [rayne5446a] at [2007-11-26 12:58:16]
# 1

If the two projects aren't in the same EAR then they are loaded with different, non-related classloaders, which isn't allowed.

In Tomcat, you can move common code into the $Catalina_Home/shared/lib/ directory which has a Classloader that is the parent of all the webapps.

Or you can put them in the same EAR.

stevejlukea at 2007-7-7 16:55:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
The two java projects are actually in the same EAR.
rayne5446a at 2007-7-7 16:55:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
What server are you using? JBoss?
evnafetsa at 2007-7-7 16:55:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I think I've actually tracked the problem down to the application class loader. The application class loader on the server will load project1.jar (dependency jar listed in a manifest), but the web module class loader will load project2.jar (web-inf/lib).

From what I've read, a class loaded by a class loader cannot reference any classes held by a child class loader. Since the web module class loader is a child of application class loader, project2.jar is not visible.

Therefore, I can specify project2.jar in the MANIFEST.MF, which will cause it to be loaded by the application class loader and it will become visible.

rayne5446a at 2007-7-7 16:55:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...