使用 Ivy 下载/安装 ant-contrib、bsf、beanshell、commons-logging

发布于 2024-09-19 22:22:29 字数 592 浏览 6 评论 0原文

我正在使用 Ant 和 Ivy 构建一个项目。 build.xml 文件依赖于 ant-contribbean 脚本框架beanshellcommons-logging

Ant 在多个位置搜索库,包括 ${user.home}/.ant/lib

如果没有,build.xml 文件中是否有任何方法可以自动下载这些库并将其安装在 ${user.home}/.ant/lib 目录中已经存在,也许使用 Ivy 本身?

谢谢,拉尔夫

I am building a project using Ant and Ivy. The build.xml file depends on ant-contrib, bean scripting framework, beanshell, and commons-logging.

Ant searches for libraries in several places, including ${user.home}/.ant/lib.

Is there any way in the build.xml file to have these libraries automatically download and install in the ${user.home}/.ant/lib directory if they are not already present, perhaps using Ivy itself?

Thanks, Ralph

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一身软味 2024-09-26 22:22:29

ant 库中唯一需要的 jar 是 ivy :-)

ivy.xml 文件中正常声明依赖项。利用配置将与 ANT 任务关联的 jar 文件集中分组:

<configurations>
    <conf name="tasks" description="Ant tasks"/>
</configurations>

<dependencies>
    <dependency org="ant-contrib" name="cpptasks" rev="1.0b5" conf="tasks->default"/>
    <dependency org="junit" name="junit" rev="3.8" conf="tasks->default"/>
    ..

build.xml 文件中,您可以从此配置创建路径

<ivy:resolve/>
<ivy:cachepath pathid="tasks.path" conf="tasks"/>

<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>

The only jar you need in your ant lib is ivy :-)

Declare your dependencies as normal within your ivy.xml file. Make use of a configuration to collectively group the jars associated with ANT tasks:

<configurations>
    <conf name="tasks" description="Ant tasks"/>
</configurations>

<dependencies>
    <dependency org="ant-contrib" name="cpptasks" rev="1.0b5" conf="tasks->default"/>
    <dependency org="junit" name="junit" rev="3.8" conf="tasks->default"/>
    ..

In your build.xml file you can create a path from this configuration

<ivy:resolve/>
<ivy:cachepath pathid="tasks.path" conf="tasks"/>

<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>
相思碎 2024-09-26 22:22:29

我在阅读 ivy 缓存文件集文档,其中指出:

请优先使用检索+
标准蚂蚁路径创建,这使得
你的构建更加独立于常春藤
(一旦工件被正确地
检索到,常春藤不需要任何
更多)。

Ivy 缓存路径文档类似地指出:

如果你想让你的构建更多
独立于常春藤,你可以
考虑使用检索任务。一次
文物已被妥善取回,
您可以使用标准 Ant 路径创建
这使得常春藤不需要任何
更多。

因此,似乎更好的答案是修改 Mark 对将检索与 ant 路径结合使用的内容的响应。大致如下:


Mark's Response (modified)

<configurations>
  <conf name="tasks" description="Ant tasks"/>
</configurations>

<dependencies>
  <dependency org="ant-contrib" name="cpptasks" rev="1.0b5"
      conf="tasks->default"/>
  <dependency org="junit" name="junit" rev="3.8" conf="tasks->default"/>
  ..

在您的 build.xml 文件中,您可以从此配置创建一个路径。

<ivy:retrieve conf="tasks"
     pattern="${dir.where.you.want.taskdef.jars}/[artifact]-[revision].[ext] />

<path id="tasks.path">
  <fileset dir="${dir.where.you.want.taskdef.jars}">
    <include name="**/*.jar"/>
  </fileset>
</path>

<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>

这甚至允许您将检索任务移动到处理依赖项的单独 ant 文件中。因此,在将依赖项检索到其目录中后,您不必依赖 ivy。

ivy 的目的是让你用它来拉下你的 jars(解析和检索)。一旦它们就位,您就可以切换回使用标准 Ant。


Note: I would just pull these dependencies into the lib directory. That would simplify the retrieve task:

<ivy:retrieve conf="tasks" />

另请注意:请访问本页的“类路径结构”部分,了解有关“标准”的更多信息蚂蚁路径创建”

I happened on this question as I was reading the Ivy cachefileset documentation, which states:

Please prefer the use of retrieve +
standard ant path creation, which make
your build more independent from ivy
(once artifacts are properly
retrieved, ivy is not required any
more).

The Ivy cachepath documentation similarly states:

If you want to make your build more
independent from Ivy, you could
consider using the retrieve task. Once
the artifacts are properly retrieved,
you can use standard Ant path creation
which makes Ivy not necessary any
more.

So, it would seem a better answer would be to modify Mark's response to something that uses retrieve in conjunction with ant paths. Something along the lines of the following:


Mark's Response (modified)

<configurations>
  <conf name="tasks" description="Ant tasks"/>
</configurations>

<dependencies>
  <dependency org="ant-contrib" name="cpptasks" rev="1.0b5"
      conf="tasks->default"/>
  <dependency org="junit" name="junit" rev="3.8" conf="tasks->default"/>
  ..

In your build.xml file you can create a path from this config

<ivy:retrieve conf="tasks"
     pattern="${dir.where.you.want.taskdef.jars}/[artifact]-[revision].[ext] />

<path id="tasks.path">
  <fileset dir="${dir.where.you.want.taskdef.jars}">
    <include name="**/*.jar"/>
  </fileset>
</path>

<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>

This would even allow you to move the retrieve task into a separate ant file that deals with dependencies. Thereby, you don't have to rely on ivy after your dependencies are retrieved into their directories.

The intention of ivy is that you use it to pull down your jars (resolve & retrieve). Once you have them in place, you can switch back to using standard Ant.


Note: I would just pull these dependencies into the lib directory. That would simplify the retrieve task:

<ivy:retrieve conf="tasks" />

Also Note: visit the 'Path-like Structures' section of this page for more on "standard ant path creation"

凉城 2024-09-26 22:22:29

我会使用 ant 来安装所有内容 INTO ant =D

只需使用 dependent="init-ant-contrib, init-ivy"

<!-- ANT-CONTRIB Auto Installer -->
<available property="ant-contrib-exists"
           file="${ant.library.dir}/ant-contrib-1.0b3.jar" />
<target name="download-ant-contrib" unless="ant-contrib-exists">
  <mkdir dir="${ant.library.dir}" />
  <get src="http://downloads.sourceforge.net/project/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fant-contrib%2Ffiles%2Fant-contrib%2F1.0b3%2F&use_mirror=cdnetworks-us-1"
       dest="${ant.library.dir}/ant-contrib-1.0b3-bin.zip"
       username="true" />
  <unzip src="${ant.library.dir}/ant-contrib-1.0b3-bin.zip"
         dest="${ant.library.dir}"
         overwrite="no" />
  <move todir="${ant.library.dir}">
    <fileset file="${ant.library.dir}/ant-contrib/*.jar" />
    <fileset file="${ant.library.dir}/ant-contrib/lib/*.jar" />
  </move>
  <delete file="${ant.library.dir}/ant-contrib-1.0b3-bin.zip" />
  <delete dir="${ant.library.dir}/ant-contrib" />
</target>
<target name="init-ant-contrib" depends="download-ant-contrib">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${ant.library.dir}/ant-contrib-1.0b3.jar" />
    </classpath>
  </taskdef>
</target>

<!-- IVY Auto Installer -->
<property name="ivy.install.version" value="2.1.0-rc2" />
<condition property="ivy.home" value="${env.IVY_HOME}">
  <isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<available file="${ivy.jar.file}" property="ivy-exists" />
<target name="download-ivy" unless="ivy-exists">
  <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">
  <!-- 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>

现在您已经有了 ant-contrib & ivy,其他一切都应该是一个简单的 ivy.xml & ivy-resolve away:

<target name="resolve" depends="init-ivy">
    <ivy:retrieve />
  </target>

我确信您可以找到类似的方法来安装您可能需要的任何 ant 任务。

I'd use ant to install everything INTO ant =D

Just use depends="init-ant-contrib, init-ivy"

<!-- ANT-CONTRIB Auto Installer -->
<available property="ant-contrib-exists"
           file="${ant.library.dir}/ant-contrib-1.0b3.jar" />
<target name="download-ant-contrib" unless="ant-contrib-exists">
  <mkdir dir="${ant.library.dir}" />
  <get src="http://downloads.sourceforge.net/project/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fant-contrib%2Ffiles%2Fant-contrib%2F1.0b3%2F&use_mirror=cdnetworks-us-1"
       dest="${ant.library.dir}/ant-contrib-1.0b3-bin.zip"
       username="true" />
  <unzip src="${ant.library.dir}/ant-contrib-1.0b3-bin.zip"
         dest="${ant.library.dir}"
         overwrite="no" />
  <move todir="${ant.library.dir}">
    <fileset file="${ant.library.dir}/ant-contrib/*.jar" />
    <fileset file="${ant.library.dir}/ant-contrib/lib/*.jar" />
  </move>
  <delete file="${ant.library.dir}/ant-contrib-1.0b3-bin.zip" />
  <delete dir="${ant.library.dir}/ant-contrib" />
</target>
<target name="init-ant-contrib" depends="download-ant-contrib">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${ant.library.dir}/ant-contrib-1.0b3.jar" />
    </classpath>
  </taskdef>
</target>

<!-- IVY Auto Installer -->
<property name="ivy.install.version" value="2.1.0-rc2" />
<condition property="ivy.home" value="${env.IVY_HOME}">
  <isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<available file="${ivy.jar.file}" property="ivy-exists" />
<target name="download-ivy" unless="ivy-exists">
  <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">
  <!-- 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>

Now that you have ant-contrib & ivy, everything else should be a simple ivy.xml & ivy-resolve away:

<target name="resolve" depends="init-ivy">
    <ivy:retrieve />
  </target>

I'm sure you can find similar methods of installing whatever ant task you might need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文