在哪里可以找到缺少可选的ant任务?
我想看看这里设置了哪些系统属性(以及哪些值),所以最简单的方法(如果不是在这里写一个新的Java程序)将会添加一些行到我的ant构建脚本中:在哪里可以找到缺少可选的ant任务?
<target name="properties">
<echoproperties/>
</target>
但是运行ant给我此错误消息:
/u/ebermann/projektoj/*-examples/build.xml:19: Problem: failed to create task or type echoproperties
Cause: the class org.apache.tools.ant.taskdefs.optional.EchoProperties was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/u/ebermann/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
好了,所以我不慌,,但不知道该怎么办。
我这里有蚂蚁1.7.1(在OpenSuse系统),而可悲的是这个版本没有文档,而且我不是root来安装这一个当前蚂蚁版本或旧版本的文档(我只是下载了它它仍然没有说这里需要哪个jar文件)。在上面列出的目录中,只有/usr/share/ant/lib
存在,但它不包含任何内容,如optional
。
我想下载必要的jar文件并将其放在我的主目录中,但在哪里可以找到它?该ant download archive包含没有这样的,我不知道在哪里可以搜索。 (我做google了一下,但没有发现任何东西。
因此,有人可以给我一些指点哪里可以找到合适的jar文件?
(我猜的解决方案是很容易的,有什么东西。只是挡着我的视线)
后vahapt的回答,我从网上下载apache repository文件,并把它变成该错误消息中提到的目录/u/ebermann/.ant/lib
再次运行ant properties
- 在相同的R-如上所述。
$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class'
org/apache/tools/ant/taskdefs/optional/EchoProperties.class
这看起来像它应该工作 - 是错误信息只是错误?
如果我把它直接到CLASSPATH,它的工作原理:
$ CLASSPATH=/u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar ant properties
Buildfile: build.xml
properties:
[echoproperties] #Ant properties
[echoproperties] #Thu Mar 10 00:46:22 CET 2011
...
[echoproperties] user.name=ebermann
[echoproperties] user.timezone=
BUILD SUCCESSFUL
Total time: 0 seconds
我不想改变我的正常CLASSPATH变量,它应该是放入此目录中工作,或者我才明白有问题?
任何想法,或者这是一个蚂蚁的错误?
(另外,为什么是这个文件无处蚂蚁文档中提及?)
编辑:
从vahapt答案后,我的ant构建文件看起来是这样的:
<project name="*-examples" basedir=".">
<target name="echoproperties.prepare">
<available property="echoproperties.works"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
/>
</target>
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${user.home}/.ant/lib">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
<target name="properties" depends="echoproperties.init">
<echoproperties/>
</target>
</project>
此重新注册,只有当它是不是已经在蚂蚁类路径的任务。 (因此,它也适用于在主目录中没有此文件的完整ant安装)。
我还是要说,This is not a bug; it is a configuration problem
不完全正确的,更是为将在该文件中指定的目录不不帮助。
还有一个有趣的现象:在${user.home}/.ant/lib
的nodeps.jar(即现在/u/ebermann/.ant/lib/ant-nodeps.jar
)已经在类路径(由${java.class.path}
所示的一个,但是这似乎没有帮助<echoproperties>
到没有这个工作。taskdef
所以,这个工程太:
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
classpath="${java.class.path}" />
</target>
当你做一个谷歌搜索,结果指向蚂蚁nodeps-1.7.1.jar
确保罐子存在,并且您已经将其添加到类路径
对于你的问题的第二部分:
解决方法1.你并不需要修改你的CLASSPATH变量。相反,你可以通过添加参数-cp [JAR文件的位置](-cp是“Java”的可执行文件)
溶液2 Jar文件是简单的ZIP文件,打开蚂蚁nodeps.jar复制它添加了内容的ant.jar扔掉蚂蚁nodeps.jar
溶液3请参见下面的示例。 taskdef是一个将jar或类加载到ClassLoader层次结构中的ant功能。 (你在使用它之前加载类,就像一个魅力)
<?xml version="1.0" encoding="ASCII"?>
<project name="Test" default="properties" basedir=".">
<target name="properties" depends="init">
<echoproperties/>
</target>
<target name="init">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${ant.library.dir}">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
</project>
谢谢...仅供参考(因为我似乎太愚蠢,无法使用谷歌),您使用了哪些关键字? – 2011-03-09 23:27:19
org.apache.tools.ant.taskdefs.optional。EchoProperties :)有时我们看不到最简单的解决方案。这就是为什么像*这样的网站已经启动并正在运行。 – vahapt 2011-03-09 23:28:30
我用我的新问题更新了这个问题 - 你(或其他人)有一些想法,为什么不使用类路径不工作? – 2011-03-09 23:52:47
我下载Ant 1.7.1,并期待与它附带的文档。在那里它将echoproperties
描述为可选任务,但没有提及获取该可选任务的jar文件的位置。
展望lib文件夹里面,我发现了ant-nodeps.jar
。显然,它包含在Ant 1.7.1中。
我建议您下载并安装Ant 1.8。由于Ant是一个Java jar文件,安装最新最好的版本并不是那么困难。
我看着我的Mac,/usr/bin/ant
是链接到/usr/share/ant/bin
和/usr/share/ant/
是链接到/usr/share/java/ant-1.8.2
。所以,我所要做的就是将/usr/share/ant/bin/
指向正确版本的Ant。
在蚂蚁1.8.2,echoproperties现在是一个标准的任务。
问题是我总是在我的配额限制下运行,所以我宁愿不安装完整的38 MB(1.7。 1)或39 MB(用于1.8.2)在我的主目录中 - 在家里我有一个当前版本,我现在安装了'ant-nodeps.jar',它只有一半MB – 2011-03-10 00:10:25
我明白了。我没有意识到你没有控制你的机器,我从来不喜欢OpenSUSE - 太多过时的程序了,最后一次看,他们仍然有Subversion 1.4和Apache httpd2的一个奇怪的实现,这使得非常设置服务器很难,我的公司最终转向Fedora/CentOS/Redhat(取决于是否需要支持,桌面系统等) – 2011-03-10 17:31:45
也许如果你命名文件ant-nodeps.jar,而没有版本,Ant可能会找到它。我相信你的问题出现了,因为Ubuntu在几个部分中封装了Ant - 核心,可选,文档,而Apache版本已经组装好几年了。现在将历史的“核心”和“可选”任务视为平等。 – 2011-03-10 00:31:37
我在OpenSUSE而不是Ubuntu上,但它可能类似。 (在我的Ubuntu系统中,我是root用户,并且也有当前的蚂蚁。)更改文件名不会改变任何内容,它看起来像ant完全忽略了这个目录。 '-lib'参数也是。 – 2011-03-10 00:36:49