0
votes

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?.

2
This is taken from the crunchify.com/… tutorial.Some guy
Check out this thread if it helps... stackoverflow.com/questions/4542529/… What does your build.properties file look like??Sid

2 Answers

2
votes

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-->
1
votes

try including fileset element as child of war element

   <fileset dir="${home.dir}/WEB-INF/libDirectory/*">
            <include name="**/*"/>
  </fileset>