简体   繁体   English

在tomcat类路径中包含web-inf / lib中的目录

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

In my webapp; 在我的webapp中; WEB-INF/lib is added in classpath by default which is fine. 默认情况下,在classpath中添加WEB-INF / lib,这很好。 Now, I want to add spring jar files in my tomcat's classpath. 现在,我想在tomcat的类路径中添加spring jar文件。 If I put all the jar files inside WEB-INF/lib; 如果我将所有jar文件放在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 ; 但是如果我想添加一个目录WEB-INF / lib / spring并将所有jar文件放在spring目录下; it doesnt work. 它不起作用。 How can I include WEB-INF/lib/spring in classpath. 如何在类路径中包含WEB-INF / lib / spring。

I would prefer to make changes in web.xml as that is very localised to my webapp. 我更愿意在web.xml中进行更改,因为它非常本地化为我的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 ) 当然我不想在catalina.properties中进行更改,因为所有jar文件都在JVM中加载(不仅仅是在类路径中添加)

You shouldn't care about how the jar files are segregated into the war file: it's only used by the container. 你不应该关心如何将jar文件分隔成war文件:它只被容器使用。 Segregating the jar files could be useful in your source project. 隔离jar文件在源项目中很有用。 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 . 但是你只需要一个构建过程(使用ant,gradle等)将所有子文件中的所有jar文件复制到WEB-INF/lib Using ant: 使用蚂蚁:

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

由于事情不关心JAR命名,另一种选择是简单地将前缀附加到JAR(即“spring-OLD JAR NAME.jar”)以保持相关JAR在没有文件夹的情况下分组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM