简体   繁体   English

与詹金斯一起使用蚂蚁制造战争时的问题

[英]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). 我正在使用Jenkins作为构建服务器(此服务器托管在其他类型的DEV环境中)。

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 . 我还将Gitlab用作存储库,在推送最新代码后,我有了Jenkins作业的钩子,该钩子会自动触发并调用此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. 出现此问题的原因是构建服务器没有任何名为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. 在我的build.xml中添加此目录的唯一原因是准备好容器特定的jar文件进行编译。

How can I fix this issue? 如何解决此问题?

Do I need to copy container specific jars on my build server? 我是否需要在构建服务器上复制特定于容器的jar? Or is there any way to tell Jenkins that not to copy this external jars but just use them for compilation. 或者有什么办法告诉詹金斯,不要复制此外部jar,而只能使用它们进行编译。

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. 如果您不想签入文件(非常明智),则可以使用Apache Ivy为您下载文件。

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. 使用像Ivy(或Maven,或类似的东西)这样的依赖管理框架将为您省去很多麻烦。 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. 设置好之后,您的ant构建将负责下载所需的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM