Apache Ant编写build.XML的自动提示 ANT DTD

大家都知道Eclipse的自动输入或者自动完成的功能是用XML的DTD文件来控制的,但是安装了ANT的插件之后会发现Apache并没有为我们直接提供书写build.xml的DTD文件,可能是由于扩张方面的考虑。在Apache的 FAQ里有提到:

An incomplete DTD can be created by the <antstructure> task - but this one has a few problems:

  • It doesn't know about required attributes. Only manual tweaking of this file can help here.
  • It is not complete - if you add new tasks via <taskdef> it won't know about it. See this page by Michel Casabianca for a solution to this problem. Note that the DTD you can download at this page is based on Apache Ant 0.3.1.
  • It may even be an invalid DTD. As Ant allows tasks writers to define arbitrary elements, name collisions will happen quite frequently - if your version of Ant contains the optional <test> and <junit> tasks, there are two XML elements named test (the task and the nested child element of <junit>) with different attribute lists. This problem cannot be solved; DTDs don't give a syntax rich enough to support this.

原文在这里(http://ant.apache.org/faq.html#dtd)

但是Ant的预订标签里面提供了生成DTD的方法。这里需要在%ANT_HOME%的lib目录下面加一个JAR包,

下载地址:http://mirrors.cnnic.cn/apache//commons/net/binaries/commons-net-3.3-bin.zip


现在新建一个build.xml


内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project default="makeantdtd">
	<target name="makeantdtd">
		<antstructure output="ant_DTD.dtd" />
	</target>
</project>


然后使用ANT命令执行这个build.xml文件,在相同路径下就会生成ant_DTD.dtd


现在用Eclipse引用这个DTD就可以实现编写build.xml的时候的自动提示了。


建议把这放在%ANT_HOME%的 etc目录下,以免误删。


Eclipse的设置在:Window--Preference--XML--XML Catalog 点击Add 输入刚才那个生成的DTD文件地址,KEY_TYPE选 public ID , 取一个名字(KEY),OK


现在按下alt+/ 就可以在有提示内容的地方弹出提示了


当然,如果想在输入的时候就直接弹出,要设置:Window--Preference--XML--XML File--Editor 在Content asist里,勾上 Automatically make suggestion, 然后在 


Prompt when these characters are inserted 里面改成 <=:abcdefghijklmnopqrstuvwxyz ${


OK!当然这样做会是Eclipse的速度变慢,喜忧参半。


转载地址:http://www.cnblogs.com/lzsu1989/archive/2011/07/26/2117718.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值