Shantanoo K
Shantanoo K

Reputation: 793

Issue while creating war using ant with Jenkins

I have a ant build script which creates a war file. The file content are as follows.

<?xml version="1.0" encoding="UTF-8"?>
<project name="TestProj" default="war" basedir=".">
<property name="project-name" value="${ant.project.name}" />
<property name="builder" value="IaasTeam" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src" />
<property name="classes-directory" value="build/classes" />
<property name="web-directory" value="WebContent" />
<property name="web-xml-file" value="WebContent/WEB-INF/web.xml" />
<property name="lib.dir" value="WebContent/WEB-INF/lib" />
<property name="catalina.home" value="../../outside/project/lib"/>

<tstamp prefix="build-info">
    <format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
    <format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<property name="build-directory" value="build" />
<path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
    <fileset dir="${catalina.home}" includes="**/*.jar"/>
</path>
<target name="clean">
     <delete dir="build"/>
</target>
<target name="compile">
      <mkdir dir="build/classes"/>
      <javac includeantruntime="false" srcdir="src" destdir="build/classes" classpathref="classpath" />
</target>
<target name="war" depends="clean,compile">
    <mkdir dir="${build-directory}" />
    <delete file="${build-directory}/${war-file-name}" />
    <war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
        <classes dir="${classes-directory}" />
        <fileset dir="${web-directory}">
            <!-- Need to exclude it since webxml is an attribute of the war tag above -->
            <exclude name="WEB-INF/web.xml" />
        </fileset>
        <manifest>
            <attribute name="Built-By" value="${builder}" />
            <attribute name="Built-On" value="${build-info.current-date}" />
            <attribute name="Built-At" value="${build-info.current-time}" />
        </manifest>
    </war>
</target>

I am using Jenkins as a build server (this is hosted on different machine kind of DEV environment).

I also use Gitlab as a repository and after pushing the latest code I have a hook for Jenkins job which gets triggered automatically and calls this build.xml.

Now the issues here is that when I run this script on my local machine everything works well but when Jenkins execute this it fails during the compilation phase giving me below error.

compile:
[mkdir] Created dir: /app/infra/jenkins/workspace/TestProj/build/classes
[javac] Compiling 49 source files to   /app/infra/jenkins/workspace/TestProj/build/classes

BUILD FAILED
/app/infra/jenkins/workspace/TestProj/build.xml:27:  /app/infra/jenkins/outside/project/lib does not exist.

The reason for this issue is the build server does not have any directoy called outside/project/lib.

The only reason of adding this directory in my build.xml is to have the container specific jar files ready for compiling.

How can I fix this issue?

Do I need to copy container specific jars on my build server? Or is there any way to tell Jenkins that not to copy this external jars but just use them for compilation.

Upvotes: 0

Views: 1169

Answers (1)

Andres Olarte
Andres Olarte

Reputation: 4380

Where would Jenkins find the jars? They need to be accessible otherwise your build will fail. If you don't want to have the files checked in (which is very sensible), you could use Apache Ivy to download them for you.

This is the most common way of handling the situation you're having. Using a dependency management framework like Ivy (or Maven, or similar) will save you a lot of headaches down the line. I recommend you have a look at their tutorial. After you set it up, your ant build will take care of downloading the files you need.

Upvotes: 1

Related Questions