如何在我的ant构建中包含本地依赖项



目前我有以下build.xml:

<project name="Bccn" default="help" basedir=".">
<!-- Define the properties used by the build -->
<property name="app.name" value="bccn" />
<property name="app.version" value="0.1-dev" />
<property name="tcserver.home" value="/home/abhishek/tomcat" />
<property name="work.home" value="${basedir}/work" />
<property name="dist.home" value="${basedir}/dist" />
<property name="src.home" value="${basedir}/src" />
<property name="web.home" value="${basedir}/web" />
<property name="lib.dir" value="${basedir}/lib" />
<target name="help">
    <echo>You can use the following targets:</echo>
    <echo>
    </echo>
    <echo>  help    : (default) Prints this message </echo>
    <echo>  all     : Cleans, compiles, and packages application</echo>
    <echo>  clean   : Deletes work directories</echo>
    <echo>  compile : Compiles servlets into class files</echo>
    <echo>  dist    : Packages artifacts into a deployable WAR</echo>
    <echo>
    </echo>
    <echo>For example, to clean, compile, and package all at once, run:</echo>
    <echo>prompt> ant all </echo>
</target>
<!-- Define the CLASSPATH -->
<path id="compile.classpath">
    <fileset dir="${tcserver.home}/bin">
        <include name="*.jar" />
    </fileset>
    <pathelement location="${tcserver.home}/lib" />
    <fileset dir="${tcserver.home}/lib">
        <include name="*.jar" />
    </fileset>
</path>
<target name="all" depends="clean,compile,dist" description="Clean work dirs, then compile and create a WAR" />
<target name="clean" description="Delete old work and dist directories">
    <delete dir="${work.home}" />
    <delete dir="${dist.home}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
    <mkdir dir="${dist.home}" />
    <mkdir dir="${work.home}/WEB-INF/classes" />
    <!-- Copy static HTML and JSP files to work dir -->
    <copy todir="${work.home}">
        <fileset dir="${web.home}" />
    </copy>
</target>
<target name="compile" depends="prepare" description="Compile Java sources and copy to WEB-INF/classes dir">
    <javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes">
        <classpath refid="compile.classpath" />
    </javac>
    <copy todir="${work.home}/WEB-INF/classes">
        <fileset dir="${src.home}" excludes="**/*.java" />
    </copy>
</target>

<target name="dist" depends="compile" description="Create WAR file for binary distribution">
    <jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${work.home}" />
</target>

现在,我将log4j作为本地依赖项包含在内,并希望在创建.war文件时将其包含在内。然而,ANT无法找到依赖项。有办法让它工作吗?很抱歉出现了基本问题,我对此一无所知。

更新(感谢我已经得到的帮助):

我不想添加"war",所以我修改了我的build.xml,如下所示:``

<target name="help">
    <echo>You can use the following targets:</echo>
    <echo>
    </echo>
    <echo>  help    : (default) Prints this message </echo>
    <echo>  all     : Cleans, compiles, and packages application</echo>
    <echo>  clean   : Deletes work directories</echo>
    <echo>  compile : Compiles servlets into class files</echo>
    <echo>  dist    : Packages artifacts into a deployable WAR</echo>
    <echo>
    </echo>
    <echo>For example, to clean, compile, and package all at once, run:</echo>
    <echo>prompt> ant all </echo>
</target>
<!-- Define the CLASSPATH -->
<path id="compile.classpath">
    <fileset dir="${tcserver.home}/bin">
        <include name="*.jar" />
    </fileset>
    <pathelement location="${tcserver.home}/lib" />
    <fileset dir="${tcserver.home}/lib">
        <include name="*.jar" />
    </fileset>
    <fileset dir="${lib.dir}">
        <include name="*.jar" />
    </fileset>
</path>
<target name="all" depends="clean,compile,dist" description="Clean work dirs, then compile and create a WAR" />
<target name="clean" description="Delete old work and dist directories">
    <delete dir="${work.home}" />
    <delete dir="${dist.home}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
    <mkdir dir="${dist.home}" />
    <mkdir dir="${work.home}/WEB-INF/classes" />
    <!-- Copy static HTML and JSP files to work dir -->
    <copy todir="${work.home}">
        <fileset dir="${web.home}" />
    </copy>
</target>
<target name="compile" depends="prepare" description="Compile Java sources and copy to WEB-INF/classes dir">
    <javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes">
        <classpath refid="compile.classpath" />
    </javac>
    <copy todir="${work.home}/WEB-INF/classes">
        <fileset dir="${src.home}" excludes="**/*.java" />
        <fileset dir="${lib.dir}" includes="*.jar" />
    </copy>
</target>

<target name="dist" depends="compile" description="Create WAR file for binary distribution">
    <jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${work.home}" />
</target>

现在ANT可以找到依赖项并对其进行编译。但是当我将其部署到Tomcat服务器时,它无法将依赖项归档。你能不能提供一些想法,告诉我如何打包依赖项,使其对Tomcat也可见?

您应该使用战争任务:

<war destfile="${warname}" webxml="war/WEB-INF/web.xml">
    <fileset dir="${work.home}"/>
    <lib dir="${lib.dir}/" includes="log4j.jar"/>
    <classes dir = "${CLASSES}" />
</war>

您可以将其配置为查找要包含在war文件中的依赖项jar,并指定web.xml文件夹的路径。你不应该将.class文件复制到war文件夹中的目的地,让war任务来帮你完成。

相关内容

  • 没有找到相关文章

最新更新