从Web-Inf/Lib文件夹中排除一些JAR包

3
我正在使用Ant进行开发。我创建了一个build.xml文件来生成Web项目的WAR文件,它能够正常工作。
然后,我进行了一些更改,将所有*.jar从WEB-INF/lib文件夹中排除,并且也可以正常工作。
现在,我需要进行一些更改,排除所有JAR文件,但保留WEB-INF/lib文件夹中的一些特殊JAR文件。这些JAR文件来自我创建的其他项目。
我的想法是排除所有的第三方JAR文件,只留下我的JAR文件在WEB-INF/lib 文件夹中。
是否有一种方法可以实现这个目的呢?
我的所有JAR文件都以"fnet"开头,因此也许我可以使用这个规则来创建一些规则,但我不知道如何操作。
这是我的Build.xml文件:
<?xml version="1.0" ?> 
<project name="warConLibs" default="build-war">
    <target name="clean">
        <delete file="c:/projweb.war"/>
        <delete file="c:/projweb_sl.war"/>
    </target>   

    <target name="build-war">
        <war destfile="c:/projweb.war" webxml="./WebContent/WEB-INF/web.xml">
            <fileset dir="./WebContent">
                <include name="**/*.*"/>            
            </fileset>

            <classes dir="./bin"/>
        </war>
    </target>

    <target name="build-war-sin-libs">
        <war destfile="c:/projweb_sl.war" webxml="./WebContent/WEB-INF/web.xml">
            <fileset dir="./WebContent">
                <include name="**/*.*"/> 
                <exclude name="**/*.jar"/>      
            </fileset>

            <classes dir="./bin"/>
        </war>
    </target>   
</project>
2个回答

1

如何排除一个jar文件的正确方法在文档中给出。如果有人遇到相同的问题,他们可以参考这个链接。

这个例子来自于文档,我们正在从lib中删除jdbc1.jar

Assume the following structure in the project's base directory:

thirdparty/libs/jdbc1.jar
thirdparty/libs/jdbc2.jar
build/main/com/myco/myapp/Servlet.class
src/metadata/myapp.xml
src/html/myapp/index.html
src/jsp/myapp/front.jsp
src/graphics/images/gifs/small/logo.gif
src/graphics/images/gifs/large/logo.gif
then the war file myapp.war created with


<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
  <fileset dir="src/html/myapp"/>
  <fileset dir="src/jsp/myapp"/>
  <lib dir="thirdparty/libs">
    <exclude name="jdbc1.jar"/>
  </lib>
  <classes dir="build/main"/>
  <zipfileset dir="src/graphics/images/gifs"
              prefix="images"/>
</war>


will consist of
WEB-INF/web.xml
WEB-INF/lib/jdbc2.jar
WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
images/small/logo.gif
images/large/logo.gif

0

你可能需要再次阅读有关 war Ant 任务的内容:https://ant.apache.org/manual/Tasks/war.html

正确的语法应该是:

<war destfile="..." webxml="...">
    <lib dir="WebContent/WEB-INF/lib">
        <include name="fnet*.jar"/>
    </lib>
    <classes dir="bin"/>
</war>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接