how to set java class loader PARENT_LAST
Asked Answered
S

3

11

i have a spring mvc web application that I need to change the class loader on. I need to change the class loader to be equal to PARENT_LAST. I am using WAS 6.1 and already have a jacl script from a previous web application I can copy to do the job.

In the last application Apache ant was used and what they did was to make the deploy dependent on running the jacl script.

In my new web application I am using maven install to create a war file and am deploying that war file to my application server.

How can I set the class loader to be PARENT_LAST using maven? I know how to do it in the console but if there was a way to do it using scripting that would be nice.

Also will this setting be placed somewhere in the war file so that on deploy of the application the setting will be picked up. This question comes from my lack of understanding of how jacl scripts work?

thanks

Sousa answered 29/1, 2014 at 4:10 Comment(1)
Not entirely sure removing the java tag can be justified?Everetteeverglade
L
18

If you are only deploying the WAR file itself you can't control this, but if you have your WAR file in an EAR file you can use the deployment.xml solution. The deployment.xml file would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1347529484613">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1347544766353" startingWeight="99" warClassLoaderPolicy="SINGLE">
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1347543866613" startingWeight="1" uri="YourWebApp.war" classloaderMode="PARENT_LAST"/>
    <classloader xmi:id="Classloader_1347543866613" mode="PARENT_LAST"/>
  </deployedObject>
</appdeployment:Deployment>

Once you are done all you need to do is to add the file in the correct location of your EAR project build assuming you are using src/main/application that would be src/main/application/META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml and build the EAR using Maven as normal.

During server deployment this will be picked up by WAS.

Lubberly answered 29/1, 2014 at 12:30 Comment(2)
thanks this is a really good answer. I now understand if I want to change the setting I need to build an ear instead of a war. It's unfortunate. But I guess the other alternative is always manually set in the web admin console after deploymentSousa
Correct. Many (but not all) deployment specific settings where WAS has its own deployment descriptors resides in the EAR file. We have found that deploying an EAR file rather than just a WAR file is better for us mainly because of the ease of deployment.Lubberly
B
3

AFAIK there is no way to preconfigure WAR for PARENT_LAST during assembly. Classloading policy is specified during deployment, thus the way of setting it depends on how application is deployed.

Changing the policy using the script is straightforward. Scripts are run using wsadmin tool. The Jython snippet below does the job. It can easily be converted to Jacl.

dep = AdminConfig.getid('/Deployment:app_name/')
depObject = AdminConfig.showAttribute(dep, 'deployedObject')
classldr = AdminConfig.showAttribute(depObject, 'classloader')
AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']])
AdminConfig.save()
Bookbinder answered 29/1, 2014 at 10:1 Comment(1)
To have PARENT_LAST apply to inner wars (if you deployed an EAR), add AdminConfig.modify(depObject, [['warClassLoaderPolicy', 'SINGLE']]); as the third line.Catholicon
S
1

Websphere uses deployment.xml file to govern deployment setting of each module in an ear file. You can change the classloader setting in deployment.xml at the following path:

/MyTestEAR/META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml

I do not know how you can configure that in Maven.

Syrupy answered 29/1, 2014 at 4:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.