目前我有这样的配置:
构建.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-->
构建.属性:
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/