Morning@Weblog

10/28/2004

提升Ant build文件灵活性的方法(2)

Filed under: — site admin @ 10:43 am

有时候我们需要面对不同操作系统平台的部署和构建,比如在windows和unix平台下,我们可以分别编写两个build文件,不过更为灵活的作法是,利用ant的<os>,然后在target中加上if属性,这样就可以实现仅用一个build文件实现多平台的构建了:

<condition property="os.windows">
    <os family="windows"/>
</condition>
<condition property="os.unix">
    <os family="unix"/>
</condition>
<target name="..." if="os.windows">
    ... ...
</target>
<target name="..." if="os.unix">
    ... ...
</target>

BTW:看了anthillpro的build.xml,未免让人觉得有些遗憾,看起来作者是过分依赖<antcall>了,这是有悖于ant的精神的。

提升Ant build文件灵活性的方法

Filed under: — site admin @ 9:21 am

今天在看到了一条有关Ant使用技巧的blog,说到了利用filterset和filter实现在构建过程中即时替换token的技巧:

<target name="config">
    <copy todir="${build.prod.dir}">
      <fileset dir="${config.dir}">
        <include name="*.properties" />
        <include name="*.xml" />
      </fileset>
      <filterset begintoken="%" endtoken="%">
        <filter token="HIBERNATE.DRIVER"
                value="${hibernate.connection.driver_class}" />
        <filter token="HIBERNATE.URL"
                value="${hibernate.connection.url}" />
        ... ...
      </filterset>
    </copy>
</target>

这里要替换的token位于目标文件,以%开始和结束,而替换的字串(properties)则位于某个properties文件中。这是一种十分常见的提升ant build文件灵活性的方法。另外,利用<replace>也可以实现同样的效果:

<target name="mkpropertyfile">
     <copy file="etc/conf.properties.tmpl" tofile="etc/conf.properties" />
     <replace file="etc/conf.properties"
              replacefilterfile="${build.properties}" />
</target>

target首先根据template文件创建一个实例文件,然后再作替换。${build.properties}对应的文件包含了所有要替换的token及对应的value。并且replace还会根据目标文件的时间戳决定是否替换。
另外,filter也提供了从属性文件导入的方式。具体方法可以参考ant的在线文档

10/19/2004

一个Jsp Tag的错误

Filed under: — site admin @ 10:39 am

Tomcat在解析Jsp页面时报错如下:
According to TLD or attribute directive in tag file, attribute page does not accept any expressions

说的是对应tag的属性不支持表达式传入。解决的办法是,在tld文件的相应tag的相应属性中加上rtexprvalue属性并设置为true,比如:

<tag>
 <name>CustomTag</name>
 ……
 <attribute>
  <name>AttName</name>
  <rtexprvalue>true</rtexprvalue>
 </attribute>
</tag>

网上说这个和Tomcat的版本也有关系(5.x),我用的恰好是5.0.27,不过这个没有证实过。

Powered by WordPress