簡體   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