02 July 2008

Using OC4J War File Manifest.mf Class-Path

There seemed to be some confusion around this area, so I posted a small example of using Manifest.mf Class-Path settings from a WAR file to OTN yesterday.

http://www.oracle.com/technology/tech/java/oc4j/10130/how_to/webapp-manifest-loading.zip

This example was build and tested against an OC4J 10.1.3 instance -- however it should work in the same way against 10.1.2 and 9.0.x releases. The app itself won't deploy to the earlier versions since the deployment files are using XSD. However the principle should be the same.

The use of OC4J 10.1.3 enables you to run classloader queries to observe the loader tree, see where code-sources are being loaded from, see which code-source classes are located in, etc.

Update: 3-July-2008

By removing any XSD elements from the deployment descriptors, the application referenced above can be rebuilt and successfully deployed to OC4J 10.1.2, whereupon the application works in exactly the same way as it does on 10.1.3. The only difference is in the output of the ClassLoader().toString method.

When running in 10.1.2, the output from the testservlet and testclass.jsp pages looks is shown below. In the output, you can see that the code-sources foobar.jar and myservlet.jar are loaded from the root level of the application deployment directory, as configured in the META-INF/MANIFEST.MF file; whereas that the simple.jar is loaded from the WEB-INF/lib directory of the web application as expected.

Note: the output has been formatted slightly to make it more presentable in this page view.
Test Class Access

Class Loader

sab.demo.warmanifest.beans.Foo
[ClassLoader: [
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\foobar.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\myservlet.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\webapp\WEB-INF\lib\simple.jar archive]
]]

sab.demo.warmanifest.beans.Bar
[ClassLoader: [
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\foobar.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\myservlet.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\webapp\WEB-INF\lib\simple.jar archive]
]]

sab.demo.warmanifest.beans.Simple
[ClassLoader: [
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\foobar.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\myservlet.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\webapp\WEB-INF\lib\simple.jar archive]
]]

sab.demo.warmanifest.web.TestServlet
[ClassLoader: [
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\foobar.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\myservlet.jar archive],
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\webapp\WEB-INF\lib\simple.jar archive]
]]

org.apache.log4j.Logger
[ClassLoader: [
[D:\java\oc4j-1012\j2ee\home\applications\webapp-manifest-loading\log4j-1.2.15.jar archive]
]]

oracle.jdbc.pool.OracleDataSource
sun.misc.Launcher$AppClassLoader@a39137

javax.servlet.http.HttpServlet
sun.misc.Launcher$AppClassLoader@a39137

No comments: