我想看看这里设置了哪些系统属性(以及哪些值),所以最简单的方法(如果不是在这里写一个新的Java程序)将会添加一些行到我的ant构建脚本中:在哪里可以找到缺少可选的ant任务?
<target name="properties">
<echoproperties/>
</target>
但是运行ant给我此错误消息:
/u/ebermann/projektoj/stackoverflow-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="stackoverflow-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>
也许如果你命名文件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