Java 我可以在 ibm-web-bnd.xmi 文件中为 WebSphere 设置类加载器策略吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/813202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:46:53  来源:igfitidea点击:

Can I set the classloader policy for WebSphere in the ibm-web-bnd.xmi file?

javawebsphereclassloader

提问by pkaeding

I have a JEE application that runs on WAS 6. It needs to have the class loader order setting to "Classes loaded with application class loader first", and the WAR class loader policy option set to "Single class loader for application".

我有一个在 WAS 6 上运行的 JEE 应用程序。它需要将类加载器顺序设置为“首先使用应用程序类加载器加载的类”,并将 WAR 类加载器策略选项设置为“应用程序的单个类加载器”。

Is it possible to specify these options inside the EAR file, whether in the ibm-web-bnd.xmi file or some other file, so the admin doesn't need to change these setting manually?

是否可以在 EAR 文件中指定这些选项,无论是在 ibm-web-bnd.xmi 文件中还是在其他一些文件中,以便管理员不需要手动更改这些设置?

Since the app is deployed via an automated script, and the guy who is in charge of deployment is off site, and also for some other political reasons, this would greatly help!

由于该应用程序是通过自动脚本部署的,负责部署的人不在现场,而且出于其他一些原因,这将非常有帮助!

采纳答案by pkaeding

Thanks to @Matthew Murdoch's answer, I was able to come up with a solution. Here it is, in case it helps someone else.

感谢@Matthew Murdoch 的回答,我想出了一个解决方案。在这里,以防它帮助其他人。

I created a deployment.xml like this:

我创建了一个如下的 deployment.xml:

<?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_1241112964096">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1241112964096" startingWeight="1" warClassLoaderPolicy="SINGLE">
    <classloader xmi:id="Classloader_1241112964096" mode="PARENT_LAST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1241112964096" startingWeight="10000" uri="AGS.war">
      <classloader xmi:id="Classloader_1241112964097"/>
    </modules>
  </deployedObject>
</appdeployment:Deployment>

Make sure to change the name of your WAR file(s) to match (mine is called AGS.war).

确保更改您的 WAR 文件的名称以匹配(我的名为 AGS.war)。

I also changed the numbers in the xmi:idattributes, to be sure they are unique, though I'm not sure it it really matters that they be unique across applications.

我还更改了xmi:id属性中的数字,以确保它们是唯一的,尽管我不确定它们在应用程序中是否唯一是否真的很重要。

Then, I put the deployment.xml file in the root of my EAR file, via ANT:

然后,我通过 ANT 将 deployment.xml 文件放在我的 EAR 文件的根目录中:

    <ear destfile="${artifactsDir}/${earName}.ear" appxml="${projectName}_EAR/application.xml">
        <fileset dir="${artifactsDir}" includes="${warName}.war"/>
        <fileset dir="${projectName}_EAR/" includes="deployment.xml"/>
    </ear>

回答by Matthew Murdoch

Edit (2):The WebSphere Application Server Toolkit (AST)is a tool you can use to enhance an EAR file with this information (see for example the 'Configure an Enhanced EAR' section in this document).

编辑(2):WebSphere Application Server的工具包(AST)是一个工具,你可以用它来加强与该信息的EAR文件(例如参见“配置增强型EAR”一节本文件)。

Edit (1):This postsuggests that the 'Classes loaded with application class loader first' (the PARENT_LAST setting) can be set in the deployment.xml file within the EAR.

编辑 (1):这篇文章建议可以在 EAR 内的 deployment.xml 文件中设置“首先使用应用程序类加载器加载的类”(PARENT_LAST 设置)。

If you have control over the automated deployment scripts this can be done. Below is some wsadmin jython code for setting the web module class loader order to 'Classes loaded with application class loader first' (interestingly the setting is called PARENT_LAST which is what it was labelled in previous versions of the admin console...).

如果您可以控制自动部署脚本,则可以这样做。下面是一些 wsadmin jython 代码,用于将 Web 模块类加载器的顺序设置为“首先使用应用程序类加载器加载的类”(有趣的是,该设置称为 PARENT_LAST,它在管理控制台的早期版本中被标记为...)。

wsadmin example (jython):

wsadmin 示例(jython):

def getWebModule(config, applicationName):
    webModules = config.list('WebModuleDeployment').
         split(system.getProperty('line.separator'))
    for webModule in webModules:
        if (webModule.find(applicationName) != -1):
            return webModule
    return None

applicationName = "<Your application name here>"

webModule = getWebModule(AdminConfig, applicationName)
if (webModule != None):
    AdminConfig.modify(webModule, "[[classloaderMode PARENT_LAST]]")
    AdminConfig.save()
else:
    print "Error: Cannot find web module for application: " + applicationName

回答by tiwari.vikash

Check out this link. There are different ways to set class loader policy using Jython based on your server version - http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frxml_7libapp4.html

看看这个链接。根据您的服务器版本,有多种使用 Jython 设置类加载器策略的方法 - http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express。 doc%2Finfo%2Fexp%2Fae%2Frxml_7libapp4.html

回答by Matt Campbell

Similar to the answer from pkaeding, I discovered as follows, not specific to a particular .war by name, but useful when applying to whatever is the default .war in the .ear file. (.ear files with one .war file in them have only that .war, so naming the .war isn't necessary in the entry.) This approach may be good for situations where you may need to re-name of the .war project later for some reason, and so you wouldn't need to worry about updating the deployment.xmlfile. I found the deployment.xmlfile buried inside a cell reference directory trail; dunno if it's fine as shown when the file is placed at directory level META-INFand no deeper.

与 pkaeding 的答案类似,我发现如下,并非特定于特定的 .war 名称,但在应用于 .ear 文件中的任何默认 .war 时很有用。(包含一个 .war 文件的 .ear 文件只有那个 .war,因此在条目中命名 .war 不是必需的。)这种方法可能适用于您可能需要重命名 .war 的情况出于某种原因稍后进行项目,因此您无需担心更新deployment.xml文件。我发现该deployment.xml文件隐藏在单元格引用目录路径中;不知道当文件放置在目录级别META-INF并且没有更深时,它是否可以正常显示。

In my particular case, I found deployment.xmlin my .ear project at:

在我的特殊情况下,我deployment.xml在我的 .ear 项目中找到了:

<project_root>\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

<project_root>\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

The content of the file looks a lot like:

该文件的内容看起来很像:

<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_1262775196208">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment"
    xmi:id="ApplicationDeployment_1262775196208" startingWeight="10">
      <classloader xmi:id="Classloader_1262775196208" mode="PARENT_LAST" />
  </deployedObject>
</appdeployment:Deployment>

The line:

线路:

<classloader xmi:id="Classloader_1262775196208" mode="PARENT_LAST" />

originally read:

原文如下:

<classloader xmi:id="Classloader_1262775196208" mode="PARENT_FIRST" />

Note no reference to any .war is being made. As pkaeding mentioned, you shouldn't expect the various id numbers to be the same for you.

请注意,没有引用任何 .war。正如 pkaeding 所提到的,您不应该期望各种 ID 号码对您来说是相同的。