Reputation: 1088
I am creating an ant script to build and deploy a project. My project structure is as follows:
Projectname
--src
--tst
--lib ( I have 5 jars here)
--resources
--WebContent
--META-INF
--WEB-INF
--lib (I have 3 jars here)
--properties
--templates
--stylesheets
--web.xml
My requirement is I have to write an ant script to build the project and create a war file in the staging environment (not local). The war should contain all the jar files available in the classpath ( classpath has more than 50 jars). But when I run my ant script it shows me only 8 jars, that are available in lib folders and does not include the jars from classpath.
How to add classpath while creating a War file? Below is the script I have written for creating a war.
<target name="war" description="Bundles the application as a WAR file" depends="build">
<echo> === PACKAGE WAR ====== </echo>
<delete dir="target" failonerror="false"/>
<mkdir dir="target"/>
<war destfile="target/test.war" needxmlfile="false" >
<fileset dir="WebRoot">
<include name="**/*.*"/>
</fileset>
<lib dir ="lib">
<include name="**/*.*"/>
</lib>
<classes dir="WebContent/WEB-INF/classes"/>
</war>
</target>
Classpath is as follows in the ant script.
<property name="ExternalJars.location" value="../ExternalJars"/>
<path id="Services.classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>
Upvotes: 1
Views: 5053
Reputation: 1653
I found a solution by using mappedresources
which a bit uncomfortable but works
<war destfile="target/test.war" needxmlfile="false" >
<fileset dir="WebRoot" />
<lib dir ="lib" />
<classes dir="WebContent/WEB-INF/classes"/>
<mappedresources>
<path refid="Services.classpath"/>
<chainedmapper>
<flattenmapper />
<globmapper from="*.jar" to="WEB-INF/lib/*.jar" />
</chainedmapper>
</mappedresources>
</war>
Upvotes: 0
Reputation: 36
Try to add in task:
<war destfile="target/test.war" needxmlfile="false" >
<fileset dir="WebRoot">
<include name="**/*.*"/>
</fileset>
<path>
<path refid="Services.classpath"/>
</path>
<lib dir ="lib">
<include name="**/*.*"/>
</lib>
<classes dir="WebContent/WEB-INF/classes"/>
</war>
Upvotes: 2
Reputation: 36
Where is located your 50 jars? Try to add your classpath folder like a in your task. Something like this:
<war destfile="target/test.war" needxmlfile="false" >
<fileset dir="WebRoot">
<include name="**/*.*"/>
</fileset>
<fileset dir="${classpath_folder}">
<include name="*.jar"/>
</fileset>
<lib dir ="lib">
<include name="**/*.*"/>
</lib>
<classes dir="WebContent/WEB-INF/classes"/>
</war>
Upvotes: 0