gpt4 book ai didi

java - 如何从我的项目中获取和使用 Apache Ivy.jar 文件,而不将它放在我的 .ant 文件夹中?

转载 作者:行者123 更新时间:2023-11-30 07:31:33 25 4
gpt4 key购买 nike

目前我有这样的配置:

build.xml:

<!-- Ivy settings start-->

<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>


<target name="download-ivy" unless="offline" description="Download Ivy">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>


<target name="init-ivy" depends="download-ivy" description="Initialize Ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>

<target name="update" depends="init-ivy" description="Download project dependencies">
<!-- edited for brevity -->

<ivy:retrieve pattern="war/WEB-INF/lib/[artifact]-[revision].[ext]" />
<!-- edited for brevity -->
</target>


<target name="clean-all" depends="clean" description="Purge ivy cache">
<ivy:cleancache/>
</target>

<!-- Ivy settings end-->

build.properties:

ivy.install.version=2.2.0
ivy.home=${user.home}/.ant
ivy.jar.dir=${ivy.home}/lib
ivy.jar.file=${ivy.jar.dir}/ivy-${ivy.install.version}.jar

Ivy .xml:

<ivy-module version="2.0">
<info organisation="org.apache" module="hello-ivy"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.1" conf="default->master"/>

</dependencies>
</ivy-module>

这意味着 Ivy 将被下载到我的 ${user.home}/.ant/lib 并从那里使用。

我怎样才能将它下载到我的项目库(例如 war/WEB-INF/lib)并从那里使用它,这样我的所有文件都在一起而不是散落在我的计算机上?

最佳答案

Ivy 是 ANT 的插件。

可以使用替代目录,但是,您必须按如下方式运行 ANT,以便 ANT 从其替代下载位置获取 ivy jar。

ant -lib $APP_DIR/lib .....

参见 ANT manual有关 ANT 如何管理插件库的详细信息。

补充说明:

Ivy 在以下目录下存储下载文件的缓存 $HOME/.ivy2/cache。可以使用 caches 指定此目录的替代位置ivy 设置文件中的指令。

关于java - 如何从我的项目中获取和使用 Apache Ivy.jar 文件,而不将它放在我的 .ant 文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7285148/

25 4 0