Mark Comix
Mark Comix

Reputation: 1898

Exclude some JARs from Web-Inf/Lib Folder

I'm starting with Ant. I created a build.xml to generate a WAR file of a Web Project and it worked OK.

Then, I made some change to exclude all *.jar from WEB-INF/lib Folder and also works OK.

Now I need to make the changes to exclude all JARs files, but leave some especial JARs in WEB-INF/lib Folder. This JARs are from other project created by me.

The idea es exclude all third parties JARs and only leave my own JARs inside WEB-INF/lib folder.

There is some way to do that?

All my Jars start with "fnet" so maybe I can use that to create some rule, but I don't know how to do that

This is my 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>

Upvotes: 3

Views: 4405

Answers (2)

Learner
Learner

Reputation: 21393

The correct way to exclude a jar file is given in the documentation. If anyone face same issue, they can refer to this link.

This example is taken from the documentation, here we are removing jdbc1.jar from 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

Upvotes: 0

Isaac
Isaac

Reputation: 16736

You may want to read again about the war Ant task: https://ant.apache.org/manual/Tasks/war.html

The correct syntax would be:

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

Upvotes: 0

Related Questions