Paŭ*_*ann 12 ant task optional
我想看看这里设置了哪些系统属性(以及哪些值),所以最简单的方法(如果不在这里编写新的Java程序)将在我的ant构建脚本中添加一些行:
<target name="properties">
<echoproperties/>
</target>
Run Code Online (Sandbox Code Playgroud)
但是运行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
Run Code Online (Sandbox Code Playgroud)
好吧,所以我不要惊慌,但不知道该怎么办.
我这里有Ant 1.7.1(一个OpenSUSE系统),遗憾的是没有这个版本的文档,而且我不是root用来安装当前的ant版本或旧版本的文档(我刚刚下载了它,它仍然可以不要说这里需要哪个jar文件).在上面列出的目录中,只/usr/share/ant/lib存在,但它不包含任何内容optional.
我想下载必要的jar文件并将其放在我的主目录中,但在哪里可以找到它?该蚂蚁下载存档包含不一样的是,我不知道还有什么地方进行搜索.(我有点谷歌,但没有找到任何东西.
那么,有人可以给我一些指针,找到合适的jar文件吗?
(我想这个解决方案非常简单,有些东西只是阻碍了我的观点.)
在vahapt回答之后,我从apache存储库下载了该文件,并将其放入/u/ebermann/.ant/lib错误消息中提到的目录中.ant properties再次运行- 与上面相同的结果.
$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class'
org/apache/tools/ant/taskdefs/optional/EchoProperties.class
Run Code Online (Sandbox Code Playgroud)
这看起来应该工作 - 错误信息是错误的吗?
如果我将它直接放入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
Run Code Online (Sandbox Code Playgroud)
我不想更改我的正常CLASSPATH变量,它应该通过将其放入此目录,或者我是否理解错误?
任何想法,或者这是一个蚂蚁虫?
(另外,为什么ant文档中没有提到这个文件?)
编辑:
从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>
Run Code Online (Sandbox Code Playgroud)
只有当它不在ant类路径中时,才会重新注册该任务.(因此它也适用于在主目录中没有此文件的完整ant安装).
我仍然会说这This is not a bug; it is a configuration problem不完全正确,甚至更多,因为将文件放在指定的目录中没有帮助.
还有一个有趣的现象:在该nodeps.jar ${user.home}/.ant/lib(即现在/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>
Run Code Online (Sandbox Code Playgroud)
当您进行谷歌搜索时,结果指向ant-nodeps-1.7.1.jar
确保jar存在并且您已将其添加到类路径中
对于问题的第二部分:
解决方案1.您无需修改CLASSPATH变量.相反,您可以通过添加参数-cp [JAR FILE LOCATION](-cp 用于"java"可执行文件)来添加它
解决方案2. Jar文件只是zip文件,打开ant-nodeps.jar将其内容复制到ant.jar throw离开ant-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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21000 次 |
| 最近记录: |