如何包括我ant构建本地依赖性 [英] How to include local dependencies in my ant build

查看:130
本文介绍了如何包括我ant构建本地依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在present我有以下的build.xml:

At present I have the following 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是无法找到的依赖。有没有办法得到它的工作?很抱歉的基本问题,我是小白吧。

Now I included log4j as a local dependency and want to include it when I create my .war file. However, ANT is not able to find the dependency. Is there a way to get it working? Sorry for the basic question, I am a noob at it.

更新(和感谢帮助我的话):

我不想加入战争的事情,所以我修改我的build.xml如下:
        
    ``
    
    
    
    
    
    
    
    

I didn't want to add the "war" thing so I modified my build.xml as follows: ``

<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可见呢?

Now ANT can find the dependencies and compile it. However when I deploy it to a Tomcat server, it fails to file the dependencies. Can you please provide some ideas as to how I can package the dependencies so its visible to Tomcat as well?

推荐答案

您应该使用战争的任务,而不是

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

您可以配置它来寻找被列入依赖的jar放到war文件,并指定路径的web.xml文件夹。你不应该应对的.class文件,以在战争中的文件夹目的地,让战争的任务,为你做。

You can configure it to find the dependency jars to be included in your war file and to specify the path to the web.xml folder. You shouldn't be coping the .class files to the destination in the war folder, let the war task do it for you.

这篇关于如何包括我ant构建本地依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆