In part 1 or the series we created a simple skin, built an ADF-Library from it and tried to reuse it by deploying it to a WebLogic Server. This approach failed. In this part, we try another option to share a jar with
Sharing the skin with other applications
To share the skin with other application we can
- Create an ADF Library
- Add this library to the other application
- Add this library as a shared library to a WebLogic Server
- Create a normal jar
- Add this library to the other application
- Add this library as a shared library to a WebLogic Server
For this blog the way we want to use if 2b. This allows to create the skin once, deploy it to a server and use it in every other application. In the next paragraph, we try out option 1a to show the problems when reading resources from a jar file.
Using a shared skin
Option 2b
Here we create a jar file containing the skin and additional resources like images and deploy it directly to a WebLogic Server as a shared library. The advantage is, that other applications can use the skin and other resources directly and that the jar can be versioned to allow different versions of the same jar on the server.
Option 1a which we discussed in the previous chapter doesn’t work for images. However, the documentation ‘Deploying a Custom Skin File in a JAR File’ and Frank Nimphius pointed it out in e.g. 86. Reading boilerplate images and icons from a JAR or How-to share skin definition files across applications how the jar file must be structured to allow the resource servlet to read the resources. The essential sentence is
‘All image resources and CSS files must also be under the META-INF directory.’
In his article, Frank suggested using the command line jar tool to create the jar. I show how to use JDev to create the jar with the needed structure and how to deploy it to a server as a shared library.
A sample application is used to use the skin and to show an image load from the jar.
The building plan for a skin in a shared Library which can be deployed to a WebLogic server is given in the article as:
To implement the shared library approach, developers need to change their existing skin definition so it can be deployed in a JAR file. The steps for this include
– Creating a META-INF directory – Creating a trinidad-skins.xml file that defines the skins deployed with the JAR file
– Creating an META-INF/adf sub directory for images and icons served from the JAR file
– Changing the image reference in the CSS to include the “adf” directory, which makes sure images and icons are handled by the ADF Faces resource loader, which can read resources from JAR files
– JAR the META-INF directory to create the library file
Looking at the current project for the skin we see a different layout
In the article Frank instructed to create the needed folders yourself and copying or moving the files to the new structure, then to use the command line to build a jar from the structure.
I’ll show how this can be done with a special deployment descriptor from within the project. The image below shows the needed layout of the final jar file.
To transform the folder structure present in JDev to the needed structure of the final jar, we create a new deployment descriptor in JDev
In image 4 we see the first part of the solution: here we set the path inside the jar to ‘MEAT-INF’. This will guarantee the structure we need. Then we add another contributor to the list (public_html) to get everything we need into this folder. Then we use the ‘Filters’ node to select all content we need skin part
Next part is to create another path in the jar for the metadata of the skin
We add another file group for the resources
Now we can deploy the jar using the new deployment descriptor
And the jar file is created in the deploy folder. It holds all files in the right folders
Finally, we can deploy this jar to the WebLogicServer. In this case, I use the integrated WLS, but it can be any stand-alone WLS too.
The error message you see on the 7th image can be ignored. It only tells you that the library can’t be deployed as an application but only as a shared library. This is exactly what we want to do 🙂
Now the jar file is deployed on the WLS as a shared library and can be used for every application on this server.
We use the existing application from part one to consume the jar skin from the shared library and show the images deployed with the jar.
Before we go any further, we have to remove the ADF Library we added to show the problem from the project. For this open the project properties and select the ‘Library/Classpath’ node and remove the ‘ADFLibrary’ entry
The page should now look like no skin is used at all.
As we already added a skin (with the ADF Library) we don’t have to do this again. However, we have to add a library reference to configure the application to use the shared library deployed on the server. For this, we open the application descriptors and edit the ‘weblogic-application.xml’ file by double clicking the entry in the application resources section
In the ‘Shared Library Reference’ section, we add a reference to the now deployed shared jar ‘blogsharedskin’
Saving everything we don’t see any change to the page design, as the library isn’t part of the application yet. Starting the application we get
Just what we liked to see. The images are visible, checking the page with Chrome’s Dev Tools shows that the images are correctly loaded
This proves that the shared library with the skin and the images are working correctly.
To make the skin visible in JDev during development, we can add the jar we developed to the server a library. We create a library
and make sure the ‘Deploy by default’ is NOT set. Adding the library to the project
will make the skin visible in design mode
The unset checkmark prevents the jar from being packed into the WAR or EAR file. It’s just used in the IDE. That you can’t see the images is normal as there is no full server to serve the images to the design view.
Summary
In this mini-series, I showed the problem when creating a skin as ADF Library and trying to share it on a Weblogic Server. Then I showed how to create a deployment descriptor for the skin and other resources and how to deploy the resulting jar to a WebLogic Server.
The sample application can be downloaded from BlogSharedSkin. The sample was created by using JDev 12.2.1.3 but the same technique can be used in any 12.2.1.x JDev version. There is no database connection needed.