0

Pretty new to ANT and building using it. I have a Java-Jersey rest project and i have included the Jersey libraries under WEB-INF/lib. I have a build.xml for building/compiling the project.

<?xml version="1.0"?>
<project name="Ant-Test" default="Main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="src.dir" location="src" />
  <property name="lib.dir" location="" />
  <property name="build.dir" location="bin" />

  <!--
    Create a classpath container which can be later used in the ant task
  -->
  <path id="build.classpath">
    <fileset dir="${lib.dir}">
      <include name="**/*.jar" />
    </fileset>
  </path>

  <!-- Deletes the existing build directory-->
  <target name="clean">
    <delete dir="${build.dir}" />
  </target>

  <!-- Creates the  build  directory-->
  <target name="makedir">
    <mkdir dir="${build.dir}" />
  </target>

  <!-- Compiles the java code -->
  <target name="compile" depends="clean, makedir">
    <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
    <jar destfile="${build.dir}/CrunchifyRESTJerseyExample.jar" basedir="${build.dir}"/>    
    <war destfile="${build.dir}/CrunchifyRESTJerseyExample.war" webxml="WebContent/WEB-INF/web.xml">
      <classes dir="${build.dir}"/>
    </war>
  </target>



  <target name="Main" depends="compile">
    <description>Main target</description>
  </target>

</project> 

With this, i am not getting the library files in the war file. What should i add to get it in the war?.

Some guy
  • 1,210
  • 1
  • 17
  • 39
  • This is taken from the http://crunchify.com/how-to-build-restful-service-with-java-using-jax-rs-and-jersey/ tutorial. – Some guy Aug 19 '13 at 09:52
  • Check out this thread if it helps... http://stackoverflow.com/questions/4542529/how-to-include-external-libraries-in-ant-build-xml-file What does your build.properties file look like?? – Sid Aug 19 '13 at 10:11

2 Answers2

2

If you take a look on the Ant war task you can specify a <lib> element with the jars that are going to be put under WEB-INF/lib folder. So try this:

<war destfile="${build.dir}/CrunchifyRESTJerseyExample.war" webxml="WebContent/WEB-INF/web.xml">
    <classes dir="${build.dir}"/>
    <lib dir="${lib.dir}">
       <exclude name="jdbc1.jar"/>  <!-- Exclude here jars you don't want -->
    </lib>
</war>

Note: You should set your property at the begining of your script for the above task to work properly:

<property name="lib.dir" location="lib" /> <!-- Or whatever you call your project folder with the jars-->
c.s.
  • 4,786
  • 18
  • 32
1

try including fileset element as child of war element

   <fileset dir="${home.dir}/WEB-INF/libDirectory/*">
            <include name="**/*"/>
  </fileset>    
M Sach
  • 33,416
  • 76
  • 221
  • 314