In the OTN WLS General forum someone asked a question regarding using Shared Libraries to share static web resources among applications. “Basically, we are trying to load jquery, css files, shared images, and what not into a shared library for access from other Web Applications.” Shared libraries will handle this use case well. I’ve put together a basic example using a simple image that is put into a shared library that is referenced by another web application. The image in the screen shot below is from a shared library. The web application that references it simply contains the JSP and a reference to the shared library in the weblogic.xml deployment descriptor.
Here is the link to the full documentation that describes all of the options for Shared Libraries in WebLogic.
I recommend taking a look at the shared libraries that ship with WebLogic Server to use as an example. In WLS 10.3.x they are located here: <MIDDLEWARE_HOME>\wlserver_10.3\common\deployable-libraries
Here is what my META-INF/MANIFEST.MF file looks like for my example, I simply copied an existing MANFIEST.MF from jsf-1.2.war and made edits:
Manifest-Version: 1.0Specification-Title: ImagesSpecification-Version: 1.0Implementation-Title: Images ImplementationImplementation-Version: 1.0Implementation-Vendor: OracleExtension-Name: images
Here is what the packaging of the library looks like after zipping it up as a WAR file:
C:\temp\images>jar -tf images.warMETA-INF/META-INF/MANIFEST.MForalogo_small.gif
As you can see, it’s only a simple WAR file with an oracle image in the base directory with a META-INF/MANIFEST.MF file describing the library. To deploy this to the WLS, you can do that as normal other than noting that it is a library. After doing that it will show up like this in the console:
If you’re using Oracle Enterprise Pack for Eclipse and set your Windows->Preferences->Server->Runtime Environments correctly, then the existing shared libraries should be available in Preferences->WebLogic->Shared Libraries and you can add the library you just created to the list. This will allow you to edit the WEB-INF/weblogic.xml in the IDE with a dialog box, correctly specify the reference to the shared library, and deploy the shared library for you to the server if it has not been done already when you deploy the application.
<?xml version="1.0" encoding="UTF-8"?><wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"><wls:weblogic-version>10.3.2</wls:weblogic-version><wls:context-root>ImagesWeb</wls:context-root><wls:library-ref><wls:library-name>images</wls:library-name><wls:specification-version>1.0</wls:specification-version><wls:exact-match>true</wls:exact-match></wls:library-ref></wls:weblogic-web-app>
Now in the index.jsp, I can simply refer to the image as if it were in my base directory of the application like this:
Shared libraries are usually used to share code such as jars and class files in WARs and EARs, but they can also be used to share static resources. So let’s say I wanted to share a jar file, I would have a WEB-INF/lib directory in my shared library, and put any jars that I wanted my application’s to have in there. If it is an EAR file, then I would use APP-INF/lib.
You can download this extremely simple example here. I tested this with WLS 10.3.2 also known as 11g PS1.