繁体   English   中英

在旧的 Ant 项目中添加 Ivy

[英]Adding Ivy in old Ant project

我已经阅读了一些文章,但我无法理解如何为依赖项设置 Ivy 文件。 我正在处理的项目很旧,我不太了解,我生成了一半 - 一半编辑了 build.xml 文件,该文件适用于 Eclipse 编译器。 这是我第一次处理构建配置,我想将依赖项移动到 ivysettings.xml 文件并改进可以改进的地方。 我的目标是创建一个部署在 Tomcat 中的战争。

最好的方法是什么?

构建.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="Teamwork"
    xmlns:ivy="antlib:org.apache.ivy.ant">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../../../Program Files/eclipse/"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>
    <path id="Web App Libraries.libraryclasspath">
        <pathelement location="WebContent/WEB-INF/lib/Tidy.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/antlr-2.7.7.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/asm-attrs.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/asm.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/avro-1.5.1.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/aws-java-sdk-1.5.5.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/bsh-2.0b4.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/c3p0-0.9.2.1.jar"/>
        <pathelement location="WebContent/WEB-INF/lib/commons-beanutils.jar"/>
        [... other jars]
    </path>
    <path id="EAR Libraries.libraryclasspath"/>
    <path id="Teamwork.classpath">
        <pathelement location="bin"/>
        <path refid="Web App Libraries.libraryclasspath"/>
        <path refid="EAR Libraries.libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="Teamwork.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
</project>

第 1 步是摆脱那个<path id>块; 这就是您要重构为基于常春藤的解决方案的内容。 您需要一个列出您的依赖项的ivy.xml文件。 可以在此处找到一个示例-它会尽可能复杂,您的示例可能会更简单。 我建议testruntimebuild配置,除非你有迫切需要,否则你不需要更多。 然后,对于每个依赖项,找出你需要它的上下文(如果你在编译时在 cp 上需要它,'build'。如果你在运行时在 cp 上需要它,'runtime'。只放入'test'用于测试时的配置,但仅此而已(因此,通常是 junit 就是这样)。

然后在您的 ant 文件中,您希望执行以下操作:

<ivy:resolve file="buildScripts/ivy.xml" refresh="true" conf="build, runtime, test" />  
<ivy:retrieve/>

这将使那些 jars 出现在lib/testlib/runtimelib/build中。 使用 start ant 技巧来制作 object(不要明确列出每个 jar)。 当您删除依赖项时,这确实会造成严重破坏,因为这不会使 jar 文件消失,但它可能比 ant clean 更简单(除了build之外,现在还应该删除lib目录)。 有一些方法可以使 ant <path> object 脱离配置,但这更复杂。

暂无
暂无

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

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