Including a directory inside web-inf/lib in tomcat classpath

大憨熊 提交于 2019-12-05 02:24:17

问题


In my webapp; WEB-INF/lib is added in classpath by default which is fine. Now, I want to add spring jar files in my tomcat's classpath. If I put all the jar files inside WEB-INF/lib; it works fine. But if I want to add a directory WEB-INF/lib/spring and put all jar files inside spring directory ; it doesnt work. How can I include WEB-INF/lib/spring in classpath.

I would prefer to make changes in web.xml as that is very localised to my webapp. Surely I will not want to make changes in catalina.properties because there all the jar files are loaded in JVM ( not just added in classpath )


回答1:


You shouldn't care about how the jar files are segregated into the war file: it's only used by the container. Segregating the jar files could be useful in your source project. But then you just need to have a build process (using ant, gradle, whatever) that copies all the jar files from all the subdirectories into WEB-INF/lib. Using ant:

<copy todir="web/WEB-INF/lib" flatten="true">
    <fileset dir="lib">
        <include name="**/*.jar"/>
    </fileset>
</copy>



回答2:


Since things don't care about JAR naming, another alternative is to simply append prefixes to the the JARs (i.e. "spring-OLD JAR NAME.jar") to keep related JARs grouped without folders.



来源:https://stackoverflow.com/questions/11296020/including-a-directory-inside-web-inf-lib-in-tomcat-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!