在tomcat类路径中包含web-inf / lib中的目录 [英] Including a directory inside web-inf/lib in tomcat classpath

查看:297
本文介绍了在tomcat类路径中包含web-inf / lib中的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络应用中;默认情况下,在classpath中添加了WEB-INF / lib,这很好。
现在,我想在tomcat的类路径中添加spring jar文件。如果我将所有jar文件放在WEB-INF / lib中;它工作正常。但是,如果我想添加一个目录WEB-INF / lib / spring并将所有jar文件放在spring目录中;它不起作用。如何在类路径中包含WEB-INF / lib / spring。

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.

我更愿意在web.xml中进行更改,因为它非常本地化为我的webapp。当然我不想在catalina.properties中进行更改,因为所有jar文件都在JVM中加载(不仅仅是在类路径中添加)

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 )

推荐答案

您不应该关心如何将jar文件分隔到war文件中:它仅由容器使用。隔离jar文件在源项目中很有用。但是你只需要一个构建过程(使用ant,gradle等)将所有子目录中的所有jar文件复制到 WEB-INF / lib 中。使用ant:

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>

这篇关于在tomcat类路径中包含web-inf / lib中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆