花钱的年华

--今天开始成为主站

肖桦ID:calvinxiu
674686次访问,排名53好友0人,关注者33
calvinxiu的文章
原创 159 篇
翻译 0 篇
转载 0 篇
评论 645 篇
江南白衣的公告

肖桦,江南白衣,开源项目SpringSide--春天的旁边发起者

最近评论
kiruba:Anyone bought from www.belrion.com before ? heard they are a paypal world seller and are macfee secured. Appreciate some feedback from anyone ^^
……
HAPPY:STRONG!
wasabi:終於等到了,呵呵~~

SpringSide2.0版本確實有點復雜了,把太多東西都封裝好,理解起來有些困難~~
6fish:终于到等到发布了
fbysss:看看谁占满了Heap?
用JDK6的jmap可以显示运行程序中对象的类型,个数与所占的大小

有时间去试一下
文章分类
    收藏
      相册
      Blog用图
      Friends
      @_@
      Anders小明
      buaawhl
      cac
      canonical
      cctvx1
      david.turing
      femto
      g9
      JohnsonQu
      Michael Chen
      Raimundox
      robbin
      SimonLei
      totodo
      wuyu
      周爱民
      孟岩
      差沙
      庄表伟
      落魄的程序员
      透明
      郁也风
      铁手
      银狐999
      飞云小侠
      存档
      软件项目交易
      订阅我的博客
      XML聚合  FeedSky
      订阅到鲜果
      订阅到Google
      订阅到抓虾
      订阅到BlogLines
      订阅到Yahoo
      订阅到GouGou
      订阅到飞鸽
      订阅到Rojo
      订阅到newsgator
      订阅到netvibes

      原创 交互式的ant 调用与自写的Ant Task收藏

      新一篇: 2005年阅读的网站RSS与schedule | 旧一篇: 用Groovy Template 生成代码 2nd

            写完代码生成的框架,少不了需要ant来调用。写完之后值得一记的东西有三:

      一、《Ant--The Definitive Guide 2nd》是本不错的cookbook

      二、与用户进行交互式输入而不是逼着用户改build.xml

      下面的代码运行时,ant会提问"What is the name of your POJO?",让用户输入属性PojoName的值。

      <input message="What is the name of your POJO (i.e. Person)?" addproperty="PojoName"/>

      三,写Ant Task

      写Ant Task其实很简单,看看下面这篇Turtorial就可以了。

      http://ant.apache.org/manual/tutorial-writing-tasks.html

      上文可浓缩到三句话里:
      1.写一个Java类,继承于org.apache.tools.ant.Task。
      2.实现execute()方法,Ant就会进行调用。
      3.参数要从build.xml传入时,Task类只需拥有同名的变量和setter函数,Ant就会为你注入。

      1.Ant Task的标准实现

      import org.apache.tools.ant.Task;
      public class HelloWorld extends Task
      {
      String msg;
      public void execute()
      {
        System.out.println(msg);
      }

      public void setMsg(String msg)

        this.msg = msg;
      }
      }

      将上面的文件编译打包成helloworld.jar

      build.xml调用如下

      <target description="Use the Task">
        <taskdef name="helloworld" classname="HelloWorld" classpath="helloworld.jar"/>
        <helloworld msg="Hello World"/>
      </target>

      另外:
      1.取得build.xml中的公共变量和Target名称

      String myProperty = getProject().getProperty("myProperty ");
      String targetName = getOwningTarget().getName();                                
      2.取得复合的属性就要复杂一点,该模式可以扩展到比下面复杂得多的情况。

      <target>
        <helloworld>
           <message msg="Hello "/>
           <message msg="World"/>
        </helloworld>
      </target>

      1.先定义叫Message的内部类以表示Message节点,该类有一个msg属性,同样有一个setter函数,使其可以在build.xml中赋值

      public class Message extends Object
      {
        public Message()
        {  }
        String msg;
        public void setMsg(String msg)  {    this.msg = msg;  }
        public String getMsg() {    return msg;  }
      }

      2.再根据Ant的框架,定义给Helloworld注入message的createXXX函数和持有Message列表的messages对象,ant就会为你完成自动注入。

      Vector msgs = new Vector(); 
      public Message createMessage()
      {
        Message msg = new Message();
        messages.add(msg);
        return msg;
      }

      发表于 @ 2005年07月11日 23:59:00|评论(loading...)|编辑

      新一篇: 2005年阅读的网站RSS与schedule | 旧一篇: 用Groovy Template 生成代码 2nd

      评论:没有评论。

      发表评论  


      登录
      Csdn Blog version 3.1a
      Copyright © 江南白衣