Apache Ant编写build.XML的自动提示 ANT DTD
发布日期:2022-03-03 10:44:15 浏览次数:4 分类:技术文章

本文共 1722 字,大约阅读时间需要 5 分钟。

大家都知道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  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

内容如下:

然后使用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

转载地址:https://blog.csdn.net/yangjiegreat/article/details/44785603 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:chrome 离线安装包下载
下一篇:Maven项目如何将自定义文件添加到META-INF目录下

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月07日 12时25分46秒