Shared Library jar are not loaded by Liberty

2019-09-15 05:15发布

问题:

I have spring MVC application which uses Spring 4.I deploying my application in Liberty 16.0.0.3.I have below server.xml configuration.

<server description="Default Server">
        <featureManager>
            <feature>webProfile-7.0</feature>
                <feature>localConnector-1.0</feature>
            </featureManager>


        <variable name="defaultHostName" value="localhost"/>

           <keyStore id="defaultKeyStore" password="mypassword" />

            <!-- Define an Administrator and non-Administrator -->
           <basicRegistry id="basic">
              <user name="admin" password="mypassword"/>
              <user name="nonadmin" password="mypassword"/>
           </basicRegistry>

           <!-- Assign 'admin' to Administrator -->
           <administrator-role>
              <user>admin</user>
           </administrator-role>

           <webContainer deferServletLoad="false"/>
           <applicationManager autoExpand="true"/>

            <httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
           <variable name="defaultHostName" value="localhost"/>

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

            <application type="war" location="testliberty.war" autoStart="true" context-root="/Spring4">
                <classloader  commonLibraryRef="global" delegation="parentLast"/>
            </application>
</server>

I have placed all spring specific jar's in below location. usr\shared\config\lib\global Anthoer option server\lib\global

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.liberty.sample</groupId>
        <artifactId>TestLiberty</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>war</packaging>

        <name>HelloWorld</name>
        <description>Demo project for Spring Boot</description>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <org.springframework-version>4.3.0.RELEASE</org.springframework-version>
            <runtime.scope>provided</runtime.scope>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${org.springframework-version}</version>
                <scope>${runtime.scope}</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>${runtime.scope}</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
                <scope>${runtime.scope}</scope>
            </dependency>
        </dependencies>

        <build>
            <finalName>HelloWorld</finalName>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>${java-version}</source>
                            <target>${java-version}</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <warSourceDirectory>src/main/webapp</warSourceDirectory>
                            <warName>testliberty</warName>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>


</project>

But none of this option is working.Server is not loading these jar's due to this Spring application context is not getting loaded.But same application is working fine if I package all the jar's in WEB-INF/lib folder.