Tomcat : PreResources tag not loading jars

2019-05-29 04:08发布

I am using tomcat 9, And trying to load all the project related jar's from below PreResources tag.

<Resources className="org.apache.catalina.webresources.StandardRoot" cachingAllowed="true" cacheMaxSize="100000" allowLinking="true">
<PreResources className="org.apache.catalina.webresources.DirResourceSet"
    base="D:\SomePath\apache-tomcat-9.0.0.M17-windows-x64-2\apache-tomcat-9.0.0.M17"
    internalPath="/External-lib"
    webAppMount="/WEB-INF/classes" />

The External-lib folder lies in tomcat directory as per the path mentioned in 'base'. but when application gets deployed, I get below error.

 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

This gets called from web.xml,

org.springframework.web.context.ContextLoaderListener

in tomcat lib, we have just tomcat libraries, where as rest all jar's are in External-lib folder. Since we have similar webApp and jar's are too many, we are trying to externalize them and not to load in webapp/web-inf/lib folder.

Please suggest, am I missing anything when loading the jar's from meta-inf/context.xml using PreResources element.

There is very less examples and documentation for this PreResources element. Any direction or help would be appreciated.

1条回答
老娘就宠你
2楼-- · 2019-05-29 04:57

This should have been the content of context.xml. It worked and fixed my issues.

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resources>
        <PreResources className="org.apache.catalina.webresources.DirResourceSet"
            base="SomePath\External-lib\"
            webAppMount="/WEB-INF/lib" />
    </Resources>
</Context>

"Base" is the path to the external resources and "webAppMount" is where you want to mount these resources.

查看更多
登录 后发表回答