6

私の目標は、ant ビルド スクリプトで war ファイルをビルドし、このプロジェクトが依存していることを ivy が認識している jar ファイルを含めることです。現時点で思いつく最高のコードは次のとおりです

<mkdir dir="dist/lib"/>
<ivy:retrieve pattern="dist/lib/[artifact].[ext]" sync="true"/>
<war destfile="dist/${ivy.module}.war" basedir="build" includes="**/*.class"
    webxml="${war.webxml}">
    <fileset dir="${war.web}"/>
    <lib dir="dist/lib"/>
</war>

このコードの問題は、jar を 2 回コピーすることです。一度私の dist/lib ディレクトリに入り、それが作成されたときに再び戦争に入ります。それは機能しますが、もっと良い方法があるという気持ちを揺るがすことはできません.

私がやりたいことは、次のようなものです

<ivy:cachepath pathid="locpathref.classpath"/>
<war destfile="dist/${ivy.module}.war" basedir="build" includes="**/*.class"
    webxml="${war.webxml}">
    <fileset dir="${war.web}"/>
    <lib refid="locpathref.classpath"/>
</war>

問題は、lib タグがいかなる種類の refid も取り込まないことです。アイデアはありますか、それとも余分なファイル コピーのセットで立ち往生していますか?

4

2 に答える 2

4

ここでの問題は、libタグが、そのファイルを war アーカイブのlibサブディレクトリにターゲットにするカスタムファイルセットであることです。カスタムウォータスクを作成することは可能かもしれませんが、努力する価値はないと思います。

アイビーが戦争の依存関係を管理する方法を改善したい場合は、構成を使用することをお勧めしますか?

実行時の依存関係を記述する構成を作成します。

    <ivy-module version="2.0">
    <info organisation="apache" module="hello-ivy"/>
    <configurations>
        <conf name="build" description="Libraries needed to for compilation"/>
        <conf name="war" extends="build" description="Libraries that should be included in the war file" />
    </configurations>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0" conf="build->*,!sources,!javadoc"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0" conf="build->*,!sources,!javadoc"/>
    </dependencies>
</ivy-module>

その後、 warタスクのlibタグを使用して単純に含めることができる (パターンを使用して) 専用のディレクトリにそれらを取得します。

    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]"/>

    <war destfile="${war.file}" webxml="${resources.dir}/web.xml">
        <fileset dir="${resources.dir}" excludes="web.xml"/>
        <lib dir="${lib.dir}/war"/>
    </war>

このアプローチの利点は、各プロジェクトの依存関係の ivy conf属性を使用して、jar ファイルが war ファイルに含まれるかどうかを最終的に決定できることです。ビルドファイルは気にしなくなりました。

結論として、あなたの投稿のポイントは、あなたのjarファイルの複数のコピーに対する懸念であったことを理解しています...私の提案したアプローチを使用すると、コピーがさらに複数になりますが、削除するクリーンなターゲットがある場合、これは問題ではないことを提出しますその後。

于 2010-01-23T17:37:52.823 に答える
4

Ant 1.8 を使用している場合は、ここで説明されている手法を使用できます: http://www.beilers.com/2010/06/ivy-dependency-management-lessons-learned-and-ant-1-8-mapped-資力/

例:

<war destfile="${war.full.path}" webxml="WebContent/WEB-INF/web.xml" manifest="${manifest.path}">
    <fileset dir="WebContent">
     </fileset>
    <classes dir="${build.dir}"/>

    <mappedresources>
      <restrict>
        <path refid="classpath.CORE"/>
        <type type="file"/>
      </restrict>
      <chainedmapper>
        <flattenmapper/>
        <globmapper from="*" to="WEB-INF/lib/*"/>
      </chainedmapper>
    </mappedresources>

    <zipfileset dir="src" prefix="WEB-INF/classes">
         <include name="**/resources/**/*.properties" />
         <include name="**/resources/**/*.xml" />
    </zipfileset>
</war>
于 2011-03-11T23:30:42.670 に答える