Myeclipse 中使用Ant 提示下面错误 “target xx does not exist in this pr

问题描述:

Myeclipse 中使用Ant 提示下面错误 “target xx does not exist in this project”
我在工程根目录下有一个build.xml,首先可以肯定的是这个xml文件没有任何问题,因为其他同事都可以正常使用,我以前用eclipse也出现过这样的问题,重装了tomcat插件以后问题就解决了.现在用myeclipse还是有这样的问题,我想知道问题的原因是什么,
代码相关片段:
//这一行提示target build-rm不存在,可是我们看到它的确是存在的啊.为什么会这样?
谢谢一楼的回答,我的Myeclipse版本为8.0,tomat版本为5.5.23,tomcat插件版本为V32beta3,ant使用Myeclipse自带的版本.
回aaronswon:,手动运行ant install-p3可以成功build,但是在Myeclipse我配置ANT_HOME为刚才下载且正常运行的路径还是不能运行,详见下图?
经过仔细确认,我发现OutLine中没有完全显示build.xml中所有的target,到了xx target以后下面所有的target都不能显示在outline中,target:build-rm恰巧是在xx之后,那应该就是ant解析build.xml的时候出现问题,导致build-rm这个任务不能执行.
<target name="xx" depends="xxx">
<copy file="${from}" tofile="${to}" overwrite="${boolean}" />
<!-- 这里有中文注释没错,上面很多的target也有很多类似的注释都是没有问题的-->
<copy file="${from}" tofile="${to}" overwrite="${boolean}" />
<!-- 这里的中文注释显示错误:The string "--" is not permitted within comments-->
<copy file="${from}" tofile="${to}" overwrite="${boolean}" />
</target>
1个回答 分类:综合 2014-10-28

问题解答:

我来补答
首先去apache网站上下载ant的压缩包,在本地解压
现在最新的是apache-ant-1.7.1
假如说你解压在了D盘,
目录是这样的
D:\apache-ant-1.7.1\bin
D:\apache-ant-1.7.1\docs
.等,
那么你将D:\apache-ant-1.7.1\bin添加到你电脑的path环境变量中.
这样你在CMD下就可以使用ant命令了
下面我给你做了一个测试类,和一个测试build.xml
类:
package org.apache.ant.demo;
public class Test {
private String name = "";
private String passwd = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
build.xml
类要建好包体结构,和build.xml放在一个文件夹里
如:
D:\ant\org\apache\ant\demo\Test.java
D:\ant\build.xml
这样,你在开始运行里打CMD,
D:
cd ant
在这个目录下执行ant这个命令
ant
或者带参数
ant jar jar即你的任务名
以下是我的运行结果,请参考
I:\java\samples\ant>ant
Buildfile:build.xml
compile:
[javac] Compiling 1 source file to I:\java\samples\ant\classes
jar:
[jar] Building jar:I:\java\samples\ant\javahelloant.jar
BUILD SUCCESSFUL
Total time:0 seconds
I:\java\samples\ant>ant jar
Buildfile:build.xml
compile:
[javac] Compiling 1 source file to I:\java\samples\ant\classes
jar:
[jar] Building jar:I:\java\samples\ant\javahelloant.jar
BUILD SUCCESSFUL
Total time:0 seconds
I:\java\samples\ant>
ANT相当于是一个批处理程序,可以建立很多任务,我看说明文档,它还可以自行发邮件,但我没做过那么复杂的,一般都是用来工程打包,你可以说的详细点,帮你查一下,现在你这么说,我也不是很明白.
有问题请留言
 
 
展开全文阅读
剩余:2000