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

时间:2013-01-25 14:41:28

标签: java web-applications ant

我从Ant开始。我创建了一个build.xml来生成一个Web项目的WAR文件,它运行正常。

然后,我做了一些更改,以从WEB-INF/lib文件夹中排除所有* .jar,也可以正常工作。

现在我需要进行更改以排除所有JAR文件,但在WEB-INF/lib文件夹中留下一些特殊的JAR。这个JAR来自我创建的其他项目。

这个想法排除了所有第三方JAR,只将我自己的JAR留在WEB-INF/lib文件夹中。

有一些方法可以做到吗?

我所有的罐子都以“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 个答案:

答案 0 :(得分:1)

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

此示例摘自文档,此处我们从jdbc1.jar

中删除lib
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

答案 1 :(得分: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>
相关问题