Adding dependency jars using classpath

Every Java archive file contains a file called MANIFEST.MF that is stored in the META-INF directory along with the other descriptors. In case of J2EE modules, MANIFEST.MF is a J2EE compliant way to specify class path information for J2EE module. Each utility JAR, Web Module and EJB module can specify in their MANIFEST the other JARs in the same EAR that are visible to them.

This is sample file for my HelloWorldWeb module. The HelloWorldWeb.war wants to call methods inside the HelloWorldEJBClient.jar which is packaged in same .ear file as that of HelloWorldWeb.war. So in order for HelloWorldWeb.war classes to use methods in the HelloWorldEJBClient.jar it must add it in Class-path,

Manifest-Version: 1.0
Class-Path: HelloWorldEJBClient.jar

If you dont add the .jar file in the Class-path it will result in ClassNotFoundException at runtime.

Note that the MANIFEST can only list JAR files that are stored in the EAR file. Also even though a WAR file is an archive file it cannot be listed on any MANFIEST since the java artifacts within a WAR are only visible to the same WAR.

1 comment:


awful piece of information, I had come to know about your blog from my friend vimal, mumbai,i have read atleast 13 posts of yours by now, and let me tell you, your blog gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a million once again, Regards, Difference Between Classpath and Path