java 如何配置 EAR 以访问现有的 Websphere Shared Lib?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6810908/
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-10-30 17:22:01  来源:igfitidea点击:

How to configure EAR to access exisiting Websphere Shared Lib?

javajakarta-eewebsphere

提问by Shahzeb

I am using JSF2 with Websphere 7 . I have created a shared lib successfully and have pointed application using Webpsphere Admin Console and it works successfully . But what we really want to do is to not have to point to that Shared Lib via WAS Admin Console but have some sort of application level configuration e.g in deployment.xml etc which we can point to the name of that Shared Isolated Lib and use it . I have gone through SO and google but not found any thing doing that . I however know that there are commercial application doing it but do not know how .
This question from How can I specify a shared library reference at the web module level in Websphere 6.1 deployment descriptors?is closely what I am after but I not want to specify version numbers or jar names as the answer states

我在 Websphere 7 中使用 JSF2。我已经成功创建了一个共享库,并使用 Webpsphere Admin Console 指向了应用程序并且它成功运行。但我们真正想做的是不必通过 WAS 管理控制台指向该共享库,而是具有某种应用程序级别配置,例如在 deployment.xml 等中,我们可以指向该共享隔离库的名称并使用它. 我已经通过了 SO 和谷歌,但没有发现任何这样做的事情。然而,我知道有商业应用程序在做,但不知道如何做。
这个问题来自如何在 Websphere 6.1 部署描述符中的 Web 模块级别指定共享库引用?正是我所追求的,但我不想在答案中指定版本号或 jar 名称

回答by Shahzeb

I found a way by simply following what WAS Admin Console was actually doing.

我通过简单地遵循 WAS Admin Console 的实际操作找到了一种方法。

Create a deployment.xml in your EAR file if you do not have one already . You will find a reference to class loader like below

如果您还没有,请在您的 EAR 文件中创建一个 deployment.xml。您将找到对类加载器的引用,如下所示

<classloader xmi:id="Classloader_1311552732281" mode="PARENT_FIRST">

Modify it and add reference to the shared Liberary created on server like below

修改它并添加对服务器上创建的共享库的引用,如下所示

 <classloader xmi:id="Classloader_1311552732281" mode="PARENT_FIRST">
        <libraries libraryName="JSF2_SHARED_LIB" sharedClassloader="true"/>
 </classloader>

@dbreaux has also shown a way .Accpeting my own answer as fits my needs better but big thanks to dbreaux too for advice.

@dbreaux 也展示了一种方法。接受我自己的答案以更好地满足我的需求,但也非常感谢 dbreaux 的建议。

回答by dbreaux

Is the issue just that you don't want to have to configure each application separately, or that you don't want to use the admin console at all? You can associate a shared library with an entire server, which might be preferable to doing it for each app.

问题是您不想单独配置每个应用程序,还是根本不想使用管理控制台?您可以将共享库与整个服务器相关联,这可能比为每个应用程序执行此操作更可取。

The other way to create those application associations is in the WebSphere-specific .xmi deployment files. These are created when you deploy but can also be included in WAR/EAR files. I don't know if that would help you at all. If it would, the official way to create them ahead of time is using one of the Deployment Tools, but since they're just XML, you may feel comfortable creating them manually.

创建这些应用程序关联的另一种方法是在特定于 WebSphere 的 .xmi 部署文件中。这些是在您部署时创建的,但也可以包含在 WAR/EAR 文件中。我不知道这是否对你有帮助。如果可以,提前创建它们的官方方法是使用其中一种部署工具,但由于它们只是 XML,您可能会觉得手动创建它们会很舒服。

回答by u4229693

To append extra details to Shahzeb's answer: My environment: Websphere 8.5; Windows 7;(Eclipse Luna to generate testing .war file)

在 Shahzeb 的回答中附加额外的细节:我的环境:Websphere 8.5;Windows 7;(Eclipse Luna 生成测试 .war 文件)

I have installed the war file exported from eclipse on websphere server by websphere console. Then exported it again and unpack it to see what websphere automatically add to it to generate EAR.

我已经通过 websphere 控制台在 websphere 服务器上安装了从 eclipse 导出的 war 文件。然后再次将其导出并解压缩以查看websphere 自动添加到其中以生成EAR 的内容。

[folder]META-INF
  [folder]ibmconfig
  [file]application.xml
  [file]ibm-application-bnd.xmi
  [file]ibm-application-runtime.props
  [file]MANIFEST.MF
  [file]was.module
  [file]was.policy
  [file]was.webmodule

[file]myWAR.war

And the file deployment.xml is placed in ..\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

并且文件 deployment.xml 被放置在 ..\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp\

whose content in form of

其内容形式为



<?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_1417052686904">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1417052686904" deploymentId="0" startingWeight="1" binariesURL="$(APP_INSTALL_ROOT)/[server service name]Cell/myWAR.ear" useMetadataFromBinaries="false" enableDistribution="true" createMBeansForResources="true" reloadEnabled="false" appContextIDForSecurity="href:[server service name]Cell/myWAR" filePermission=".*\.dll=755#.*\.so=755#.*\.a=755#.*\.sl=755" allowDispatchRemoteInclude="false" allowServiceRemoteInclude="false" asyncRequestDispatchType="DISABLED" standaloneModule="true" enableClientModule="false">
    <targetMappings xmi:id="DeploymentTargetMapping_1417052686904" enable="true" target="ServerTarget_1417052686904"/>
    <classloader xmi:id="Classloader_1417052686904" mode="PARENT_FIRST"/>
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1417052686904" deploymentId="1" startingWeight="10000" uri="myWAR.war" containsEJBContent="0">
      <targetMappings xmi:id="DeploymentTargetMapping_1417052686905" target="ServerTarget_1417052686904"/>
      <classloader xmi:id="Classloader_1417052686905"/>
    </modules>
    <properties xmi:id="Property_1417052686904" name="metadata.complete" value="true"/>
  </deployedObject>
  <deploymentTargets xmi:type="appdeployment:ServerTarget" xmi:id="ServerTarget_1417052686904" name="server1" nodeName="[server service name]"/>
</appdeployment:Deployment>

(Since I have no reputation, I have to do it all in text.. )

(因为我没有名气,只能用文字来做..)