I am making a war of a project but i want that classes within that war be picked from specified location and also a jar file A.jar to be picked from custom location i am doing something like this ....
<target name="war" depends="a-jar">
<war destfile="D:/JBOSSHOME/project.war" webxml="${project-location}/web/WEB-INF/web.xml">
<fileset dir="${project-location}/web" >
<exclude name="${project-location}/web/WEB-INF/lib/A.jar"/>
<exclude name="${project-location}/web/WEB-INF/classes/**/*.class"/>
</fileset>
<lib dir="${jarsLocation}"></lib>
<classes dir="D:/JBOSSHOME/project/build/classes"/>
</war>
</target>
but in the resultant war i am getting 2 A.jar files and also classes are getting copied from ${project-location}/web/WEB-INF/classes instead of the classes dir that i have provided...
Any help would be much appreciated...
The exclude shouldn't include the root directory of your file set:
<fileset dir="${project-location}/web" >
<exclude name="WEB-INF/lib/A.jar"/>
<exclude name="WEB-INF/classes/**/*.class"/>
</fileset>
Related
I am working on an open source project that uses ANT which can perform all kind of useful targets.
One of them generate an executable jar and a webapp directory in the same directory. I tried to find ways to package that webapp directory with the jar, there is tons of information out there but non of them provide a example that fits my problem.
Open Refine is a great data cleansing tool, you can start it using a script that takes different start up arguments.
It is built using jetty Web server and Web app for UI. Architecture here.
It uses ANT for deployment management, where there is a task that create the Linux kit:
<target name="linux" depends="jar, prepare_webapp">
<mkdir dir="${linux.dir}"/>
<copy todir="${linux.dir}/server/lib">
<fileset dir="${server.lib.dir}">
<include name="**/*.jar"/>
</fileset>
</copy>
<copy file="${build.dir}/${fullname}-server.jar" tofile="${linux.dir}/server/lib/${fullname}-server.jar"/>
<copy todir="${linux.dir}/webapp">
<fileset dir="${built.webapp.dir}">
<include name="**"/>
</fileset>
</copy>
<mkdir dir="${linux.dir}/licenses"/>
<fixcrlf srcDir="${basedir}/licenses" destDir="${linux.dir}/licenses" eol="lf"/>
<fixcrlf srcDir="${basedir}" destDir="${linux.dir}" eol="lf">
<include name="refine"/>
<include name="refine.ini"/>
<include name="README.txt"/>
<include name="LICENSE.txt"/>
</fixcrlf>
<mkdir dir="${dist.dir}"/>
<tar longfile="gnu" compression="gzip" destfile="${dist.dir}/openrefine-linux-${version}.tar.gz">
<tarfileset dir="${linux.dir}/.." filemode="755">
<include name="${release.name}/refine"/>
</tarfileset>
<tarfileset dir="${linux.dir}/..">
<include name="${release.name}/**"/>
<exclude name="${release.name}/refine"/>
</tarfileset>
</tar>
</target>
This task creates a web directory, which is used in the previous task:
<target name="prepare_webapp" depends="jar_webapp, build">
<mkdir dir="${built.webapp.dir}" />
<copy todir="${built.webapp.dir}">
<fileset dir="${webapp.dir}">
<include name="**/*"/>
<exclude name="WEB-INF/classes/**"/>
<exclude name="WEB-INF/lib-src/**"/>
<exclude name="WEB-INF/lib/icu4j*.jar"/>
</fileset>
</copy>
and the Jar are prepared using another ANT target as following:
<target name="jar_webapp" depends="prepare_jar, build_webapp">
<jar destfile="${build.dir}/${fullname}.jar" basedir="${webapp.classes.dir}"/>
</target>
The result of running ant linux is an executable jar and a webapp directory, Is it possible to package the entire thing as one fat jar?
I have a folder structure like this,
samples/soap-client/target/layout/srcdist/etc/wsdl/v1/...
samples/soap-client/target/layout/srcdist/etc/wsdl/v2
samples/soap-client/target/layout/war/.....
i want to copy the all content of layout folder to another location except wsdl folder. my code is like this
<copy todir="${pse-layout.dir}/sdk/partnersdk/new-soap-client">
<fileset dir="samples/soap-client/target/layout">
<exclude name="**/**/wsdl/"/>
<include name="**/*"/>
</fileset>
</copy>
but this is not working.this copies the whole content of layout folder including wsdl folder. please help me.
Try to change your copy task to:
<copy todir="${pse-layout.dir}/sdk/partnersdk/new-soap-client">
<fileset dir="samples/soap-client/target/layout">
<include name="**/*"/>
<exclude name="**/wsdl/**"/>
</fileset>
</copy>
This will exclude all the wsdl folders you have in your layout folder.
i'm generating a war with an Ant script but i noticed that the Ant's war size is almost double the size of the war created by Eclipse. And now i'm want to know if it's possible to reduce this size.
This is the war script:
<war destfile="${docflow4-web-home}/deploy/docflow.war" webxml="${docflow4-web-home}/web/WEB-INF/web.xml">
<classes dir="${docflow4-web-home}/web/WEB-INF/classes" />
<lib dir="${docflow4-web-home}/web/WEB-INF/lib"/>
<fileset dir="${docflow4-web-home}/web">
<include name="**/*.*"/>
</fileset>
</war>
My answer to my problem was to remove the "class" and the "lib" tag from the script, they were duplicating the files
<war destfile="${docflow4-web-home}/deploy/docflow.war" webxml="${docflow4-web-home}/web/WEB-INF/web.xml">
<fileset dir="${docflow4-web-home}/web">
<include name="**/*.*"/>
</fileset>
</war>
My project folder has a bunch of dependent jars in:
/lib/someapi-1.1.1/main.jar
/lib/someotherapi-2.2.2/api-2.2.2.jar
/lib/...
I build a JAR file and my application requires that the dependent jars get included in the final jar in the /lib folder within the jar, so the final jar should have a structure something like:
/org/me/myclasses.class
/lib/main.jar
/lib/api-2.2.2.jar
How do I get the /lib/*.jar files flattened an included in the /lib directory of my final jar file?
CLARIFICATION
I'm essentially just trying to get a set of resource files flattened and added to a given directory in my final jar.
In case you wanted do skip the copy step, you could do it this way. It uses <mappedresources> to flatten from the source lib directories to the classes/lib area.
<jar destfile="${dist}/MyOneBigJar.jar">
<fileset dir="${classes}"/>
<mappedresources>
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
<chainedmapper>
<flattenmapper />
<globmapper from="*" to="classes/lib/*" />
</chainedmapper>
</mappedresources>
</jar>
The easiest way I see is to copy allyour jars to a temporary folder using the copy task and its flatten attribute, and to include the jars of this temporary directory into the destination jar.
ADDED DETAIL added by asker
Here's what the final ANT target looks like (for future reference):
<target name="dist">
<mkdir dir="${classes}/lib"/>
<copy flatten="true" todir="${classes}/lib" includeemptydirs="false">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</copy>
<jar destfile="${dist}/MyOneBigJar.jar">
<fileset dir="${classes}"/>
</jar>
</target>
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>
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
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>