首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ivy下载/安装ant-contrib、bsf、beanshell、commons-logging

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

Stack Overflow用户
提问于 2010-09-16 22:49:50
回答 3查看 2.2K关注 0票数 2

我正在使用Ant和Ivy构建一个项目。build.xml文件依赖于ant-contribbean scripting frameworkbeanshellcommons-logging

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

有没有办法在build.xml文件中让这些库自动下载并安装在${user.home}/.ant/lib目录中(如果它们还不存在),比如使用Ivy本身?

谢谢,拉尔夫

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-02-03 12:06:57

当我阅读Ivy cachefileset documentation时,我偶然发现了这个问题,上面写道:

请优先使用retrieve +标准蚂蚁路径创建,这使您的构建更加独立于ivy (一旦工件被正确检索,就不再需要ivy )。

Ivy cachepath文档类似地声明:

如果你想让你的构建更加独立于常春藤,你可以考虑使用检索任务。一旦正确检索到工件,就可以使用标准的Ant路径创建,这样就不再需要Ivy了。

因此,更好的答案似乎是将Mark的响应修改为使用retrieve和ant路径的东西。类似于下面的内容:

Mark的响应(已修改)

代码语言:javascript
复制
<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文件中,您可以从此配置创建路径

代码语言:javascript
复制
<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。

注意:我只需将这些依赖项拉入lib目录。这将简化检索任务:

代码语言:javascript
复制
<ivy:retrieve conf="tasks" />

另请注意:请访问

票数 3
EN

Stack Overflow用户

发布于 2010-09-17 07:12:02

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

ivy.xml文件中如常声明依赖项。使用配置对与ANT任务相关联的jars进行集中分组:

代码语言:javascript
复制
<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文件中,您可以从此配置创建路径

代码语言:javascript
复制
<ivy:resolve/>
<ivy:cachepath pathid="tasks.path" conf="tasks"/>

<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>
票数 5
EN

Stack Overflow用户

发布于 2011-07-01 05:19:55

我会使用ant将所有内容安装到ant =D中

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

代码语言:javascript
复制
<!-- 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&amp;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:

代码语言:javascript
复制
<target name="resolve" depends="init-ivy">
    <ivy:retrieve />
  </target>

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3727854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档