how to set java class loader PARENT_LAST

不想你离开。 提交于 2019-11-26 16:09:13

问题


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


回答1:


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.




回答2:


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()



回答3:


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.



来源:https://stackoverflow.com/questions/21421916/how-to-set-java-class-loader-parent-last

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!