Ant 之 生成 ant.dtd 文件 (转载)

Is there a DTD that I can use to validate my build files?

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 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.

虽然dtd会限制ant的可扩展性但是在语法提示的诱惑下还是生成了这个DTD;

方法大致如下:

1.建立一个build.xml

2.输入内容:

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

3.到build.xml所在目录下执行ant_home%/bin/ant makedtd

4.BUILD FAILED!发生一个NoClassDefFoundError错误,大致是说org/apache/commons/net/ftp/FTPClientConfig没找到

但是project.dtd还是生成了,我这里这个ANT1.7生成的115KB。

5.为了解决这个问题首先查得FTPClientConfig是apache的commons-net包的,于是下载http://apache.mirror.phpchina.com/commons/net/binaries/commons-net-1.4.1.zip,放到ant_home的lib目录下 ,再次构建 OK ,没有错误提示project.dtd生成202KB。

不过好像给XMLSpy挂上还是没有语法提示 -_-

6.仔细看了一下原来生成的DTD里边有几处问题。

   1)第六行<!ELEMENT project (target | %tasks; | %types;)*>

   此行末尾的‘*’号应该为‘+’号因为每个build.xml都应该起码有一个<project>元素

   2)根据XMLSpy提示,有个定义<!ELEMENT targe EMPTY>。

   3) 根据XMLSpy提示<!ELEMENT FTP.........>这块也有问题,由于平时基本不会用到因此删掉。

OK 现在已经是个良好格式(well-formet)的project.dtd文件了。

现在通过XMLSpy根据此project.dtd 建立的build.xml就具备了一般的语法提示功能了。

转载于:https://my.oschina.net/caiyuan/blog/7911

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值