使用Liberty为Web应用程序定义类加载器

时间:2016-10-26 19:41:35

标签: spring-boot websphere-liberty

我有一个应用程序Rest服务这是一场战争,我想在Liberty profile中部署它。目前我正在打包应用程序以及战争中的所有spring jar。     但我们想要创建一个共享库,并将所有这些jar移动到共享库中,并使用应用程序中的类加载器引用共享库。

server.xml
<application location ="restapp-1.0.0-SNAPSHOT.war" context-root="/myrestapp/mytestapp">
        <classloader commonLibraryRef="global"/>
    </application>

    <library id="global">
        <fileset includes="*.jar" dir="${server.config.dir}/lib/global"></fileset>
    </library>

Also I have placed all the jar dependencies under server/config/lib/global.

I am having below entries in my ibm-web-ext.xml which is in webapp/WEB-INF/

<web-ext
    xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
    version="1.0">


    <reload-interval value="3"/>
    <context-root uri="/myrestapp/mytestapp" />
    <enable-directory-browsing value="false"/>
    <enable-file-serving value="true"/>
    <enable-reloading value="true"/>
    <enable-serving-servlets-by-class-name value="false" />

</web-ext>


Same config is working fine if I bundle all the jar's as part of WAR and place the war in dropins folder. But Sharedlibrary configuration is not working.

1 个答案:

答案 0 :(得分:2)

您可以通过将以下配置放在server.xml中来为WebSphere Liberty中的应用程序定义共享库:

<library id="springLib">
 <fileset dir="${server.config.dir}/libs/spring/" includes="*.jar"/>
</library>

<application location ="restService.war">
  <classloader commonLibraryRef="springLib"/>
</application>

使用此配置,restService.war中的代码将能够从springLib共享库加载类。

另请参阅:Liberty: Shared Libraries