??xml version="1.0" encoding="utf-8" standalone="yes"?>午夜亚洲av永久无码精品,亚洲人成在线电影,亚洲中文无码线在线观看http://www.tkk7.com/wiflish/category/11012.htmlLoving Life! Loving Coding!zh-cnTue, 01 Apr 2008 10:34:46 GMTTue, 01 Apr 2008 10:34:46 GMT60JPA annotationhttp://www.tkk7.com/wiflish/archive/2008/04/01/190053.html想飞的鱼想飞的鱼Tue, 01 Apr 2008 05:12:00 GMThttp://www.tkk7.com/wiflish/archive/2008/04/01/190053.htmlhttp://www.tkk7.com/wiflish/comments/190053.htmlhttp://www.tkk7.com/wiflish/archive/2008/04/01/190053.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/190053.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/190053.html只要@Id的annotation在getterҎ(gu)上,将使用getterҎ(gu)上的annotationQ忽略属性别的annotation?br />

想飞的鱼 2008-04-01 13:12 发表评论
]]>
[转]Java中的内部cd匿名c?/title><link>http://www.tkk7.com/wiflish/archive/2007/07/01/127344.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Sun, 01 Jul 2007 03:40:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2007/07/01/127344.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/127344.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2007/07/01/127344.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/127344.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/127344.html</trackback:ping><description><![CDATA[转:(x)http://hi.baidu.com/chillll/blog/item/7b939444593b034e500ffe02.html<br /><br /><div id="buvyxdq" class="cnt">提vJava内部c(<strong>Inner Class</strong>Q可能很多h不太熟?zhn)Q实际上cM的概念在C++里也有,那就是嵌套类Q?strong>Nested Class</strong>Q, 关于q两者的区别与联p,在下文中?x)有?gu)。内部类从表面上看,是在类中又定义了一个类Q下文会(x)看到Q内部类可以在很多地方定义)Q而实际上q没有那? 单,乍看上去内部cM乎有些多余,它的用处对于初学者来说可能ƈ不是那么显著Q但是随着对它的深入了解,你会(x)发现Java的设计者在内部cn上的是? 心良苦。学?x)用内部类Q是掌握Java高~程的一部分Q它可以让你更优雅地设计你的E序l构。下面从以下几个斚w来介l:(x)<br clear="all" /><ul><li><font size="+1"><strong>W一ơ见?/strong></font></li></ul>    <table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>interface</strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />     <font color="#0000ff"><strong>int</strong></font> value();<br /> }</p><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>interface</strong> Destination {<br />     <font color="#0000ff"><strong>String</strong></font> readLabel();<br /> }</p><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods {<br />     <font color="#0000ff"><strong>private</strong></font><strong>class</strong> Content implements <span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />         <font color="#0000ff"><strong>private int</strong></font> i = 11;<br />         <font color="#0000ff"><strong>public int</strong></font> value() { <br />             <strong><font color="#0000ff">return</font></strong> i; <br />          }<br />      }</p><p class="unnamed1">    <font color="#0000ff"><strong>protected</strong></font><strong>class</strong> GDestination <strong><font color="#0000ff">implements</font></strong> Destination {<br />         <font color="#0000ff"><strong>private</strong></font><font color="#cccccc"><strong><font color="#000000">String</font></strong></font> label;<br />         <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />             <font color="#0000ff"><strong>label</strong></font> = whereTo;<br />          }<br />         <font color="#0000ff"><strong>public</strong></font><strong>String</strong> readLabel() { <br />             <font color="#0000ff"><strong>return</strong></font> label; <br />          }<br />      }</p><p class="unnamed1">    <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />         <font color="#0000ff"><strong>return </strong></font><strong>new</strong> GDestination(s);<br />      }<br />     <font color="#0000ff"><strong>public</strong></font><strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span></strong> cont() {<br />         <font color="#0000ff"><strong>return</strong></font><strong>new</strong> Content();<br />      }<br /> }</p><p class="unnamed1"><font color="#0000ff"><strong>class</strong></font> TestGoods {<br />     <font color="#0000ff"><strong>public</strong></font><strong><font color="#0000ff">static</font> void main</strong>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />          Goods p = <strong><font color="#0000ff">new</font></strong> Goods();<br />         <span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> c = p.cont();<br />          Destination d = p.dest("Beijing");<br />      }<br /> } </p></td></tr></tbody></table>      ? q个例子里类Content和GDestination被定义在了类Goods内部Qƈ且分别有着protected和private修饰W来控制讉KU? 别。Content代表着Goods的内容,而GDestination代表着Goods的目的地。它们分别实C两个接口Content? Destination。在后面的mainҎ(gu)里,直接?<span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> c和Destination dq行操作Q你甚至q这两个内部cȝ名字都没有看见!q样Q内部类的第一个好处就体现出来了—?strong><font color="#0000ff">隐藏你不惌别h知道的操?/font></strong>Q也卛_装性? <p align="left">     同时Q我们也发现了在外部cM用范围之外得到内部类对象的第一个方法,那就是利用其外部cȝҎ(gu)创徏q返回。上例中的cont()和dest()Ҏ(gu)是q么做的。那么还有没有别的方法呢Q当然有Q其语法格式如下Q?/p><table class="code" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1" align="left">outerObject=<strong><font color="#0000ff">new </font></strong>outerClass(Constructor Parameters);</p><p class="unnamed1" align="left">outerClass.innerClass innerObject=outerObject.new InnerClass(Constructor Parameters);</p></td></tr></tbody></table><p align="left">     注意在创建非静态内部类对象Ӟ一定要先创v相应的外部类对象。至于原因,也就引出了我们下一个话题—?/p><ul><li><font size="+1"><strong>非静态内部类对象有着指向其外部类对象的引?/strong></font></li></ul><p>对刚才的例子E作修改Q?/p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1" align="left"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods {</p><p class="unnamed1" align="left">   <font color="#0000ff"><font color="#ff0000"><strong>private valueRate=2;</strong></font></font></p><p class="unnamed1" align="left">    <strong><font color="#0000ff">private</font> class </strong>Content<strong> implements </strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />         <strong><font color="#0000ff">private int</font></strong> i = <font color="#ff0000"><strong>11*valueRate;</strong></font><br />         <strong><font color="#0000ff">public int </font></strong>value() { <br />             <font color="#0000ff"><strong>return</strong></font> i; <br />          }<br />      }</p><p class="unnamed1" align="left">    <strong><font color="#0000ff">protected</font> class</strong> GDestination <strong>implements</strong> Destination {<br />         <strong><font color="#0000ff">private String</font></strong> label;<br />         <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />             <strong><font color="#0000ff">label</font></strong> = whereTo;<br />          }<br />         <strong><font color="#0000ff">public String</font></strong> readLabel() { <br />             <font color="#0000ff"><strong>return</strong></font> label; <br />          }<br />      }</p><p class="unnamed1" align="left">    <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />         <strong><font color="#0000ff">return</font> new</strong> GDestination(s);<br />      }<br />     <font color="#0000ff"><strong>public</strong></font><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> cont() {<br />         <font color="#0000ff"><strong>return</strong></font><font color="#0000ff"><strong><font color="#000000">new</font></strong></font> Content();<br />      }<br /> }</p></td></tr></tbody></table><p align="left"></p>      修改的部分用蓝色昄恕T谡饫镂颐歉鳪oodscd加了一个private成员变量valueRateQ意义是货物? 价值系敎ͼ在内部类Content的方法value()计算价值时把它乘上。我们发玎ͼvalue()可以讉KvalueRateQ这也是内部cȝW二? 好处—?strong><font color="#0000ff">一个内部类对象可以讉K创徏它的外部cd象的内容</font></strong>Q? 甚至包括U有变量Q这是一个非常有用的Ҏ(gu),为我们在设计时提供了更多的思\和捷径。要惛_现这个功能,内部cd象就必须有指向外部类对象的引用? Java~译器在创徏内部cd象时Q隐式的把其外部cd象的引用也传了进dƈ一直保存着。这样就使得内部cd象始l可以访问其外部cd象,同时q也是ؓ(f)什 么在外部cM用范围之外向要创建内部类对象必须先创建其外部cd象的原因?<p align="left">     有h?x)问Q如果内部类里的一个成员变量与外部cȝ一个成员变量同名,也即外部cȝ同名成员变量被屏蔽了Q怎么办?没事QJava里用如下格式表达外部cȝ引用Q?/p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1">outerClass.this</td></tr></tbody></table><p align="left">有了它,我们׃怕这U屏蔽的情况了?/p><ul><li><strong><font size="+1">静态内部类</font></strong></li></ul><p>     和普通的cMP内部cM可以有静态的。不q和非静态内部类相比Q区别就在于静态内部类没有了指向外部的引用。这实际上和C++中的嵌套cd相像 了,Java内部cMC++嵌套cL大的不同在于是否有指向外部的引用这一点上Q当然从设计的角度以?qing)以它一些细节来讲还有区别?/p><p>     除此之外Q在M非静态内部类中,都不能有静态数据,静态方法或者又一个静态内部类Q内部类的嵌套可以不止一层)。不q静态内部类中却可以拥有q一切。这也算是两者的W二个区别吧?/p><ul><li><strong><font size="+1">局部内部类</font></strong></li></ul><p>是的QJava内部cM可以是局部的Q它可以定义在一个方法甚至一个代码块之内?/p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods1 {<br />      <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />           <font color="#0000ff"><strong>class</strong></font> GDestination <strong><font color="#000000">implements</font></strong> Destination {<br />                <font color="#0000ff"><strong>private String</strong></font> label;<br />                <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />                     <font color="#0000ff"><strong>label</strong></font> = whereTo;<br />                 }<br />                <font color="#0000ff"><strong>public String</strong></font> readLabel() { <strong><font color="#0000ff">return</font></strong> label; }<br />            }<br />           <font color="#0000ff"><strong>return new </strong></font>GDestination(s);<br />       }</p><p class="unnamed1">     <font color="#0000ff"><strong>public static</strong></font><font color="#000000"><strong>void main</strong></font>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />            Goods1 g= <strong><font color="#0000ff">new</font></strong> Goods1();<br />            Destination d = g.dest("Beijing");<br />       }<br /> }</p></td></tr></tbody></table><p>     上面是q样一个例子。在Ҏ(gu)dest中我们定义了一个内部类Q最后由q个Ҏ(gu)q回q个内部cȝ对象。如果我们在用一个内部类的时候仅需要创建它的一个对象ƈ创给外部Q就可以q样做。当?dng)定义在方法中的内部类可以使设计多样化Q用途绝不仅仅在q一炏V?/p><p>下面有一个更怪的例子Q?/p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong><font color="#000000">class</font></strong> Goods2{<br />      <font color="#0000ff"><strong>private</strong></font><strong><font color="#000000">void</font></strong> internalTracking(<strong><font color="#0000ff">boolean</font></strong> b) {<br />            if(b) {<br />                <font color="#0000ff"><strong><font color="#000000">class</font></strong></font> TrackingSlip {<br />                     <font color="#0000ff"><strong>private String</strong></font> id;<br />                      TrackingSlip(<strong><font color="#0000ff">String</font></strong> s) {<br />                           id = s;<br />                      }<br />                     <font color="#00ff00"><strong><font color="#0000ff">String</font></strong></font> getSlip() { <strong><font color="#0000ff">return</font></strong> id; }<br />                 }<br />                 TrackingSlip ts = <strong><font color="#0000ff">new</font></strong> TrackingSlip("slip");<br />                <font color="#0000ff"><strong>String</strong></font> s = ts.getSlip();<br />            } <br />       }</p><p class="unnamed1">     <font color="#0000ff"><strong>public void</strong></font> track() { internalTracking(<strong><font color="#0000ff">true</font></strong>); }</p><p class="unnamed1">     <font color="#0000ff"><strong>public static</strong></font><strong>void main</strong>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />            Goods2 g= <strong><font color="#000000">new</font></strong> Goods2();<br />            g.track();<br />       }<br /> }</p></td></tr></tbody></table><p>     你不能在if之外创徏q个内部cȝ对象Q因已经出了它的作用域。不q在~译的时候,内部cTrackingSlip和其他类一样同时被~译Q只不过它由它自q作用域,出了这个范围就无效Q除此之外它和其他内部类q没有区别?/p><ul><li><font size="+1"><strong>匿名内部c?/strong></font></li></ul><p>     java的匿名内部类的语法规则看上去有些古怪,不过如同匿名数组一P当你只需要创Z个类的对象而且用不上它的名字时Q用内部类可以使代码看上去z清楚。它的语法规则是q样的:(x)</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1"><font color="#0000ff"><strong>new</strong></font> interfacename(){......}; ?<strong><font color="#0000ff">new</font></strong> superclassname(){......};</td></tr></tbody></table><p>下面接着前面l箋举例子:(x)</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1"><font color="#0000ff"><strong>public class</strong></font> Goods3 {<br />      <font color="#0000ff"><strong>public</strong></font><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> cont(){<br />           <font color="#0000ff"><strong>return</strong></font><strong><font color="#0000ff">new</font></strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span>(){<br />                <font color="#0000ff"><strong>private int</strong></font> i = 11;<br />                <font color="#0000ff"><strong>public int</strong></font> value() { <br />                     <font color="#0000ff"><strong>return</strong></font> i; <br />                 }<br />            };<br />       }<br /> }</td></tr></tbody></table><p>q里Ҏ(gu)cont()使用匿名内部cȝ接返回了一个实C接口<span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span>的类的对象,看上ȝ十分简z?/p><p>在java的事件处理的匿名适配器中Q匿名内部类被大量的使用。例如在惛_闭窗口时加上q样一句代码:(x)</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1">frame.<strong><font color="#000000">addWindowListener</font></strong>(<strong><font color="#0000ff">new</font></strong> WindowAdapter(){<br />      <font color="#0000ff"><strong>public void</strong></font> windowClosing(WindowEvent e){<br />            System.exit(0); <br />       }<br /> });</td></tr></tbody></table><p>     有一炚w要注意的是,匿名内部cȝ于没有名字,所以它没有构造函敎ͼ但是如果q个匿名内部cȝ承了一个只含有带参数构造函数的父类Q创建它的时候必d? q些参数Qƈ在实现的q程中用super关键字调用相应的内容Q。如果你惌初始化它的成员变量,有下面几U方法:(x)</p><ol><li>如果是在一个方法的匿名内部c,可以利用q个Ҏ(gu)传进你想要的参数Q不q记住,q些参数必须被声明ؓ(f)final?</li><li>匿名内部类攚w成有名字的局部内部类Q这样它?yu)可以拥有构造函C?</li><li>在这个匿名内部类中用初始化代码块?</li></ol><ul><li><font size="+1"><strong>Z么需要内部类Q?/strong></font></li></ul><p>java内部cL什么好处?Z么需要内部类Q?/p><p>     首先举一个简单的例子Q如果你惛_C个接口,但是q个接口中的一个方法和你构想的q个cM的一个方法的名称Q参数相同,你应该怎么办?q时候,? 可以Z个内部类实现q个接口。由于内部类对外部类的所有内定w是可讉K的,所以这样做可以完成所有你直接实现q个接口的功能?/p><p>     不过你可能要质疑Q更改一下方法的不就行了吗?</p><p>     的确Q以此作计内部类的理由,实在没有说服力?/p><p>     真正的原因是q样的,java中的内部cd接口加在一P可以的解军_被C++E序员抱怨java中存在的一个问题——没有多l承。实际上QC++的多l承设计h很复杂,而java通过内部cd上接口,可以很好的实现多l承的效果?/p><p>     本文的目的只是向大家介绍一下内部类的概念以?qing)用方法,在后l文章里Q将?x)针?gu)文中的内容D更多具体的例子,以及(qing)介绍如何使用内部cLZ个Applicaton Framework?/p></div><img src ="http://www.tkk7.com/wiflish/aggbug/127344.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2007-07-01 11:40 <a href="http://www.tkk7.com/wiflish/archive/2007/07/01/127344.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZStruts的防止页面重复提交的代码片段http://www.tkk7.com/wiflish/archive/2007/04/12/110293.html想飞的鱼想飞的鱼Thu, 12 Apr 2007 15:00:00 GMThttp://www.tkk7.com/wiflish/archive/2007/04/12/110293.htmlhttp://www.tkk7.com/wiflish/comments/110293.htmlhttp://www.tkk7.com/wiflish/archive/2007/04/12/110293.html#Feedback9http://www.tkk7.com/wiflish/comments/commentRss/110293.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/110293.html    //防止重复提交.
   
saveToken(request);

2、在q行数据保存操作的action的方法中Q如saveҎ(gu)Q,增加如下代码Q?br />   
if(!isTokenValid(request)) {
        ActionMessages messages 
= new ActionMessages();

        messages.add(ActionMessages.GLOBAL_MESSAGE,
            
new ActionMessage("error.submit.double"));
        saveMessages(request.getSession(), messages);
        
        
//如果是重复提交,重新生成token
        saveToken(request);
        
        
return mapping.findForward("edit");
    }
    
    
//不是重复提交׃存数据,q删除该ơ提交的token
    resetToken(request);

3、在~辑记录的jsp面Q?lt;html:errors />标签Q显C错误提C?br />

想飞的鱼 2007-04-12 23:00 发表评论
]]>
[转]使用JMock来实现孤立测?/title><link>http://www.tkk7.com/wiflish/archive/2007/04/10/109632.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Tue, 10 Apr 2007 06:40:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2007/04/10/109632.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/109632.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2007/04/10/109632.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/109632.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/109632.html</trackback:ping><description><![CDATA[ <p class="entryContent">使用JMock来实现孤立测??<br /> </p> <p>我们在测试某cLQ由于它要与其他cd生联p,因此往往在测试此cȝ代码中也与之联pȝcM一h试了。这U测试,被测试的cȝ接依赖于其他 c,一旦其他类发生改变Q被试cM随之被迫改变。更重要的是Q这些其他类可能未l过试Q因此必d试q些c,才能试被测试类。这U情况下Q测? 驱动开发成为空谈。而如果其他类中也引用了被试c,我们到底先测试哪一个类Q因此,在测试中Q如果我们能被试cd立v来,使其完全不依赖于其他cȝ 具体实现Q这P我们p做到试先行Q先试哪个c,先实现哪个c,而不与之联pȝcL否已l实现?/p> <p>虚拟对象(mock object)是为此需要而诞生的。它通过JDK中的反射机制Q在q行时动态地创徏虚拟对象。在试代码中,我们可以验证q些虚拟对象是否被正地调用 了,也可以在明确的情况下Q让其返回特定的假想倹{而一旦有了这些虚拟对象提供的服务Q被试cd可以虚拟对象作为其他与之联pȝ真实对象的替w,从? L地搭v一个很完美的测试环境?/p> <p>JMock是帮助创建mock对象的工P它基于Java开发,在Java试与开发环境中有不可比拟的优势Q更重要的是Q它大大化了虚拟对象的用?/p> <p>本文中,通过一个简单的试用例来说明JMock如何帮助我们实现q种孤立试。有三个主要的类QUserQUserDAOQ及(qing) UserService。本文中Q我们只需试UserServiceQ准备虚拟UserDAO。对于UserQ由于本w仅是一个过于简单的POJOQ可 以不用测试。但如果你是一个完主义者,也可以用JMock的虚拟它。在q领域,JMock几乎无所不能?)</p> <p>User是一个POJOQ用以在视图中传输数据及(qing)映射数据库。其代码如下Q?/p> <p>package com.sarkuya.model;</p> <p>public class User {<br />     private String name;</p> <p>    public User() {<br />     }<br />     <br />     public User(String name) {<br />         this.name = name;<br />     }<br />     <br />     public String getName() {<br />         return name;<br />     }<br />     <br />     public void setName(String name) {<br />         this.name = name;<br />     }<br /> }</p> <p> <br /> UserDAO负责与数据库打交道,通过数据库保存、获取User的信息。尽我们可以不用知道JMock如何通过JDK的反机制来实现孤立试Q但? 应知道QJDK的反机制要求这些在q行时创建的动态类必须定义接口。在使用JMock的环境中Q由于我们要虚拟UserDAOQ意味着UserDAO 必须定义接口。代码如下:(x)</p> <p>package com.sarkuya.dao;</p> <p>import com.sarkuya.model.User;</p> <p>public interface UserDAO {<br />     public void saveUser(User user);<br />     public User getUser(Long id);<br /> }</p> <p>UserService存有UserDAO的引用,通过其对外提供应用的服务。相应地Q我们先定义了其接口(管在本文中Q作试c,UserService不需要有接口Q但如果以后此类需要被虚拟Q也应该带有接口Q基于此原因Q我们也为其定义了接??/p> <p>package com.sarkuya.service;</p> <p>import com.sarkuya.dao.UserDAO;<br /> import com.sarkuya.model.User;</p> <p>public interface UserService {<br />     public void setUserDAO(UserDAO userDAO);<br />     <br />     public void saveUser(User user);<br />     public User getUser(Long id);<br /> }</p> <p>可以看到Q除了setUserDAO()外,其另外的Ҏ(gu)与UserDAO一栗这是设计模式中门面模式的典型应用,应用只通过UserService提供服务Q而UserService在内部通过调用UserDAO来实现相应的功能?/p> <p>Ҏ(gu)试先行的原则,你应该先写测试,再编写实现。这里先~写实现的原因,主要是读者更加清楚我们接着要测试什么。由于本文是着重介lJMock的用,加上UserServiceImpl比较单,因此先列出其代码如下Q?/p> <p>package com.sarkuya.service.impl;</p> <p>import com.sarkuya.dao.UserDAO;<br /> import com.sarkuya.model.User;<br /> import com.sarkuya.service.UserService;</p> <p>public class UserServiceImpl implements UserService {<br />     private UserDAO userDAO;<br />     <br />     public UserServiceImpl() {<br />     }</p> <p>    public void setUserDAO(UserDAO userDAO) {<br />         this.userDAO = userDAO;<br />     }</p> <p>    public User getUser(Long id) {<br />         return userDAO.getUser(id);<br />     }</p> <p>    public void saveUser(User user) {<br />         userDAO.saveUser(user);<br />     }<br /> }</p> <p>下面是UserService的测试代码:(x)</p> <p>package com.sarkuya.service;</p> <p>import com.sarkuya.dao.UserDAO;<br /> import com.sarkuya.model.User;<br /> import com.sarkuya.service.impl.UserServiceImpl;<br /> import junit.framework.*;<br /> import org.jmock.Mock;<br /> import org.jmock.MockObjectTestCase;</p> <p>public class UserServiceTest extends MockObjectTestCase {<br />     private UserService userService = new UserServiceImpl();<br />     <br />     private Mock userDAO = null;<br />     <br />     public UserServiceTest(String testName) {<br />         super(testName);<br />     }<br />     <br />     protected void setUp() throws Exception {<br />         userDAO = new Mock(UserDAO.class);<br />         userService.setUserDAO((UserDAO)userDAO.proxy());<br />     }<br />     <br />     protected void tearDown() throws Exception {<br />     }<br />     <br />     public static Test suite() {<br />         TestSuite suite = new TestSuite(UserServiceTest.class);<br />         <br />         return suite;<br />     }<br />     <br />     public void testGetUser() {<br />         User fakeUser = new User("John");<br />         userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(fakeUser));<br />         <br />         User user = userService.getUser(1L);<br />         assertNotNull(user);<br />         assertEquals("John", user.getName());<br />     }<br />     <br />     public void testSaveUser() {<br />         User fakeUser = new User("John");<br />         <br />         userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(fakeUser));<br />         User user = userService.getUser(1L);<br />         assertEquals("John", user.getName());<br />         <br />         userDAO.expects(once()).method("saveUser").with(same(fakeUser));<br />         user.setName("Mike");<br />         userService.saveUser(user);<br />         <br />         userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(user));<br />         User modifiedUser = userService.getUser(1L);<br />         assertEquals("Mike", user.getName());<br />     }<br /> }</p> <p>此段代码有几点应注意Q?/p> <p>1、此试cȝ承了JMock的MockObjectTestCase</p> <p>2、private Mock userDAO = null;说明userDao是一个准备虚拟的对象</p> <p>3、在setup()中,userDAO.class传入Mock()后,再通过proxy()Ҏ(gu)q回一个UserDAO的代理类实例(卌拟对象实?Qƈ赋guserService</p> <p>4、在testGetUser()Ҏ(gu)中,如果我们先将W一行及(qing)W二行代码屏蔽掉Q可以看出,q是一个真实环境下的测试代码。先获取一个UserQ? 然后认光I|再确认其姓名为“John”。此Ӟ在真实环境下Q这D代码要试成功的前提必LUserDAO已经q接C数据库,然后q回一? User后传lUserService?br /> 但问题是Q到目前为止Q且不说UserDAOq未l历q接数据库这一pdJ琐而痛苦的q程Q我们甚臌未实现UserDAO的接口!那么Qؓ(f)何加上第一? ?qing)第二行代码后就可以了呢Q这正是JMock的威力所在。先实例化一个测试用的fakeUserQ然后通过一pd的指令,在第二行代码中告诉JMock? 该如何“做假”。尽这句代码很长,我们可作如下理解Q?br /> 1) userDAO.expects(once())Q我们期望userDAO的某Ҏ(gu)被执行一ơ,如果此方法未被执行,或者执行了二次以上Q测试就不会(x)通过<br /> 2) method("getUser")Q这个期望被执行一ơ的Ҏ(gu)名ؓ(f)userDAO.getUser()<br /> 3) with(eq(1L))Q执行getUser()Ҏ(gu)Ӟ认其传入的参数gؓ(f)?L?br /> 4) will(returnValue(fakeUser))Q上q条件均满后,q回一个虚假的对象Q即我们前面实例化的fakeUser<br /> M来说Q当讑֮好第二行语句后,JMock在后台监控着Q确保userDAO.getUser()必须Q且只被执行一ơ,且参数?L”已l正地传给了此Ҏ(gu)Q一旦这些条件被满Q就q回fakeUser?br /> 而在W三行,User user = userService.getUser(1L)触发所有这些条Ӟ作ؓ(f)奖励Q它接受了奖品fakeUserq赋guser对象。而下面第四行?qing)第五行均对此user对象q行试Q不通过才怪?/p> <p>5) testSaveUser()Ҏ(gu)中的原理cM。其思\是,id为?”的user从数据库中取出,其名改为“Mike”,再存回数据库Q然后再从数据库中取出此userQ确保其名字已被改变?br /> W五行userDAO.expects(once()).method("saveUser").with(same(fakeUser))比较Ҏ(gu)。首 先,with(same(fakeUser))说明Q传入参数必LfakeUser此实例,管我们在下面的语句中通过user.setName ("Mike")Q但只是改变了其name的属性,而fakeUser的实例引用ƈ未发生改变,因此可以满条g。其ơ,其后没有.will (returnValue(fakeUser))Q因为userDAO.saveUser()不需要返回Q何对象或基本数据cd?br /> 另外Q当再次执行userDAO.expects()ӞJMock重讑օ监控条g。我们也可以通过userDAO.reset()来显式是清除监控条g?/p> <p>通过以上实例代码?qing)其说明Q我们看出,用好JMock的关键是先设|监控条Ӟ再写相应的测试语句。一旦设好监控条件后Q在某段代码块执行完毕时Q? 如果监控条g未得到满I或是没有通过expects()再次重设条gQ或通过reset()来显式是清除监控条gQ测试将无法通过?/p> <p>以上介绍了JMock的基本用方法。而这U基本用法,占了全面掌握JMock所需学习(fn)的知?0%以上。关于JMock的更多细节,感兴的读者可以访问JMock的网站进一步学?fn)?/p> <img src ="http://www.tkk7.com/wiflish/aggbug/109632.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2007-04-10 14:40 <a href="http://www.tkk7.com/wiflish/archive/2007/04/10/109632.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【原创】JIRA安装(windows)http://www.tkk7.com/wiflish/archive/2007/04/01/107831.html想飞的鱼想飞的鱼Sun, 01 Apr 2007 13:49:00 GMThttp://www.tkk7.com/wiflish/archive/2007/04/01/107831.htmlhttp://www.tkk7.com/wiflish/comments/107831.htmlhttp://www.tkk7.com/wiflish/archive/2007/04/01/107831.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/107831.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/107831.html1、环境:(x)Windows XPQtomcat5.0.28Qmysql5.0.37Qapache2.0.59Q?br />2、下载j(lu)iraQhttp://downloads.atlassian.com/software/jira/downloads/atlassian-jira-enterprise-3.8-standalone.tar.gz
3、解压到一个目录,jira的根目录?JIRA_HOME%表示Qatlassian-jira-enterprise-3.8-standalone自带了tomcatQ如果已l设|过了CATALINA_HOMEQ更?JIRA_HOME%\bin\startup.bat文gQ找刎ͼ(x):okHomeQ在其下增加Q?br />cd ..
set CATALINA_HOME=%cd%
q样更改后,q行%JIRA_HOME%\bin\startup.batp启动jira自带的tomcatQ?br />4、修改连接池配置Qjira默认使用HSQLDBQ修?JIRA_HOME%\conf\server.xmlQ?br />该文g中的q接池配|更改ؓ(f)mysql的配|。如Q?br />
1 username="root"
2 password=""
3 driverClassName="com.mysql.jdbc.Driver"
4 url="jdbc:mysql://localhost/jira?useUnicode=true&amp;characterEncoding=utf-8"
注:(x)一定要加:(x)useUnicode=true&amp;amp;characterEncoding=utf-8Qƈ在c:\WINDOWS\my.iniQmysql配置文gQ中的[mysqld]部分加入Qdefault-character-set=UTF8Q即讄mysql的默认字W集为UTF8Q,否则有ؕ码?br />
5、修?JIRA_HOME%\atlassian-jira\WEB-INF\classes\entityengine.xml文gQ查找:(x)<datasource name="defaultDS" field-type-name="hsql"
      helper-class="org.ofbiz.core.entity.GenericHelperDAO"
hsql更改为:(x)mysql?br />
6、运?JIRA_HOME%\bin\startup.batQ输入:(x)http://localhost:8080Q看到jira的安装向|安装成功?br />
注:(x)
aQ将mysql5的jdbc驱动Qmysql-connector-java-5.0.5-bin.jar攑ֈ%JIRA_HOME%\common\lib目录下?br />bQmysql的安装参见:(x)http://www.tkk7.com/wiflish/archive/2006/12/26/90123.html
cQ由于jira是收费的Q启动jira自带的tomcatQ进入安装向导后Q需要输入注册码?br />




想飞的鱼 2007-04-01 21:49 发表评论
]]>
java~译和运行小工具http://www.tkk7.com/wiflish/archive/2007/03/07/102418.html想飞的鱼想飞的鱼Wed, 07 Mar 2007 07:47:00 GMThttp://www.tkk7.com/wiflish/archive/2007/03/07/102418.htmlhttp://www.tkk7.com/wiflish/comments/102418.htmlhttp://www.tkk7.com/wiflish/archive/2007/03/07/102418.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/102418.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/102418.html~译和运行javaE序的DOS批处理文件?br />java初学者编写测试代码时Q不用专门开个dosH口Q输入命令来~译和运行javaE序?br />待~译的java文g拖动到compile.bat上,p~译Q?br />待q行的class文g拖动到run.bat上,pq行?br />点击下蝲



想飞的鱼 2007-03-07 15:47 发表评论
]]>
【{】JAVA的内省(introspectorQ与反射QreflectionQ?/title><link>http://www.tkk7.com/wiflish/archive/2007/03/05/101964.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Mon, 05 Mar 2007 09:40:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2007/03/05/101964.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/101964.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2007/03/05/101964.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/101964.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/101964.html</trackback:ping><description><![CDATA[ <font color="#000000"> <div id="hfdffng" class="postTitle"> <a > <img height="13" src="http://blog.csdn.net/images/zhuan.gif" width="15" border="0" /> JAVA语言的反和内省</a> </div> <div id="ewldvbl" class="postText"> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">很多朋友在深入的接触</span> <span lang="EN-US">JAVA</span> <span style="FONT-FAMILY: 宋体">语言后就?x)发现这样两个词Q反?/span> <span lang="EN-US">(Reflection)</span> <span style="FONT-FAMILY: 宋体">和内?/span> <span lang="EN-US">(Introspector)</span> <span style="FONT-FAMILY: 宋体">Q经常搞不清楚这到底是怎么回事Q在什么场合下应用以及(qing)如何使用Q今天把q二者放在一起介l,因ؓ(f)它们二者是相辅相成的?/span> </p> <p class="MsoNormal"> <span style="FONT-FAMILY: 宋体">反射</span> </p> <p class="MsoNormal"> <span lang="EN-US"> <?xml:namespace prefix = o /?> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">相对而言Q反比内省更容易理解一炏V用一句比较白的话来概括,反射是让你可以通过名称来得到对?/span> <span lang="EN-US">(</span> <span style="FONT-FAMILY: 宋体">c,属性,Ҏ(gu)</span> <span lang="EN-US">)</span> <span style="FONT-FAMILY: 宋体">的技术。例如我们可以通过cd来生成一个类的实例;知道了方法名Q就可以调用q个Ҏ(gu)Q知道了属性名可以访问这个属性的倹{?/span> </p> <p class="MsoNormal"> <span style="FONT-FAMILY: 宋体">q是写两个例子让大家更直观的了解反射的用方法:(x)</span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568"> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">通过cd来构造一个类的实?br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Class cls_str = Class.forName(</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"java.lang.String"</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">上面q句很眼熟,因ؓ(f)使用q?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">JDBC</span> <span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">讉K数据库的人都用过</span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: Wingdings"> <span>J<br /></span> </span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Object str = cls_str.newInstance();<br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">相当?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">String str = new String();</span> </p> </td> </tr> </tbody> </table> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568"> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">通过Ҏ(gu)名来调用一个方?br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">String methodName = </span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"length"</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">;<br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Method m = cls_str.getMethod(methodName,</span> <strong> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span> </strong> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">System.out.println(</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"length is "</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">+ m.invoke(str,</span> <strong> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span> </strong> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">));<br /></span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">相当?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">System.out.println(str.length());</span> </p> </td> </tr> </tbody> </table> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">上面的两个例子是比较常用Ҏ(gu)。看C面的例子有发问了:(x)Z么要q么ȝ呢?本来一条语句就完成的事情干吗要整这么复杂?没错Q在上面的例子中实没有必要q么ȝ。不q你惛_q样一个应用程序,它支持动态的功能扩展Q也是说程序不重新启动但是可以自动加蝲新的功能Q这个功能用一个具体类来表C。首先我们必Mؓ(f)q些功能定义一个接口类Q然后我们要求所有扩展的功能cdd现我指定的接口,q个规定了应用程序和可扩展功能之间的接口规则Q但是怎么动态加载呢Q我们必让应用E序知道要扩展的功能cȝcdQ比如是</span> <span lang="EN-US">test.Func1</span> <span style="FONT-FAMILY: 宋体">Q当我们把这个类?/span> <span lang="EN-US">(</span> <span style="FONT-FAMILY: 宋体">字符?/span> <span lang="EN-US">)</span> <span style="FONT-FAMILY: 宋体">告诉应用E序后,它就可以使用我们W一个例子的Ҏ(gu)来加载ƈ启用新的功能。这是cȝ反射Q请问你有别的选择吗?</span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal"> <span lang="EN-US"> <span>       </span> </span> <span style="FONT-FAMILY: 宋体">关于Ҏ(gu)的反徏议大家看我的另外一文章?/span> <span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">利用</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Turbine</span> <span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的事件映来扩展</span> <span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Struts</span> <span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的功?/span> <span style="FONT-FAMILY: 宋体">》,地址是:(x)</span> <span lang="EN-US"> <a >http://www.javayou.com/article/CSDN/extend_struts.html</a> </span> <span style="FONT-FAMILY: 宋体">。这文章详l介l了如果通过反射来扩?/span> <span lang="EN-US">Struts</span> <span style="FONT-FAMILY: 宋体">框架的功能?/span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal"> <span style="FONT-FAMILY: 宋体">内省</span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">内省?/span> <span lang="EN-US">Java</span> <span style="FONT-FAMILY: 宋体">语言?/span> <span lang="EN-US">Bean</span> <span style="FONT-FAMILY: 宋体">cd性、事件的一U缺省处理方法。例如类</span> <span lang="EN-US">A</span> <span style="FONT-FAMILY: 宋体">中有属?/span> <span lang="EN-US">name,</span> <span style="FONT-FAMILY: 宋体">那我们可以通过</span> <span lang="EN-US">getName,setName</span> <span style="FONT-FAMILY: 宋体">来得到其值或者设|新的倹{通过</span> <span lang="EN-US">getName/setName</span> <span style="FONT-FAMILY: 宋体">来访?/span> <span lang="EN-US">name</span> <span style="FONT-FAMILY: 宋体">属性,q就是默认的规则?/span> <span lang="EN-US">Java</span> <span style="FONT-FAMILY: 宋体">中提供了一?/span> <span lang="EN-US">API</span> <span style="FONT-FAMILY: 宋体">用来讉K某个属性的</span> <span lang="EN-US">getter/setter</span> <span style="FONT-FAMILY: 宋体">Ҏ(gu)Q通过q些</span> <span lang="EN-US">API</span> <span style="FONT-FAMILY: 宋体">可以使你不需要了解这个规则(但你最好还是要搞清楚)Q这?/span> <span lang="EN-US">API</span> <span style="FONT-FAMILY: 宋体">存放于包</span> <span lang="EN-US">java.beans</span> <span style="FONT-FAMILY: 宋体">中?/span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">一般的做法是通过c?/span> <span lang="EN-US">Introspector</span> <span style="FONT-FAMILY: 宋体">来获取某个对象的</span> <span lang="EN-US">BeanInfo</span> <span style="FONT-FAMILY: 宋体">信息Q然后通过</span> <span lang="EN-US">BeanInfo</span> <span style="FONT-FAMILY: 宋体">来获取属性的描述器(</span> <span lang="EN-US">PropertyDescriptor</span> <span style="FONT-FAMILY: 宋体">Q,通过q个属性描q器可以获取某个属性对应的</span> <span lang="EN-US">getter/setter</span> <span style="FONT-FAMILY: 宋体">Ҏ(gu)Q然后我们就可以通过反射机制来调用这些方法。下面我们来看一个例子,q个例子把某个对象的所有属性名U和值都打印出来Q?/span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568"> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">/* <br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span> </span>* Created on 2004-6-29<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span> </span>*/</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">package</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">demo;</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.BeanInfo;<br /></span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.Introspector;<br /></span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.PropertyDescriptor;</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">/**<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span> </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">内省演示例子<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span> </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,159,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">@author</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">liudong<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span> </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*/</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" dir="ltr" style="MARGIN-RIGHT: 0px; TEXT-ALIGN: left" align="left"> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">class</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">IntrospectorDemo {<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span>String name;<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">static</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">void</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">main(String[] args) </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">throws</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Exception{<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">        IntrospectorDemo demo = </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">new</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">IntrospectorDemo();<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">        demo.setName(</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"Winter Lau"</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">如果不想把父cȝ属性也列出来的话,<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span> <span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">?/span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">getBeanInfo</span> <span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的第二个参数填写父类的信?br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span>BeanInfo bi = Introspector.getBeanInfo(demo.getClass(),</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Object.</span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">class</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span>PropertyDescriptor[] props = bi.getPropertyDescriptors();<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">for</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">(</span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">int</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">i=0;i<props.length;i++){<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>            </span>System.out.println(props[i].getName()+</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"="</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">+<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>                    </span>props[i].getReadMethod().invoke(demo,</span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">));<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span>}</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span>}</span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span> </span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">String getName() {<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">return</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">name;<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span>}</span> <span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-ALIGN: left" align="left"> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">void</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">setName(String name) {<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>        </span> </span> <strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">this</span> </strong> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">.name = name;<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"> <span>    </span>}<br /></span> <span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">}</span> </p> </td> </tr> </tbody> </table> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span lang="EN-US">Web</span> <span style="FONT-FAMILY: 宋体">开发框?/span> <span lang="EN-US">Struts</span> <span style="FONT-FAMILY: 宋体">中的</span> <span lang="EN-US">FormBean</span> <span style="FONT-FAMILY: 宋体">是通过内省机制来将表单中的数据映射到类的属性上Q因此要?/span> <span lang="EN-US">FormBean</span> <span style="FONT-FAMILY: 宋体">的每个属性要?/span> <span lang="EN-US">getter/setter</span> <span style="FONT-FAMILY: 宋体">Ҏ(gu)。但也ƈ不Lq样Q什么意思呢Q就是说对一?/span> <span lang="EN-US">Bean</span> <span style="FONT-FAMILY: 宋体">cLԌ我可以没有属性,但是只要?/span> <span lang="EN-US">getter/setter</span> <span style="FONT-FAMILY: 宋体">Ҏ(gu)中的其中一个,那么</span> <span lang="EN-US">Java</span> <span style="FONT-FAMILY: 宋体">的内省机制就?x)认为存在一个属性,比如cM有方?/span> <span lang="EN-US">setMobile</span> <span style="FONT-FAMILY: 宋体">Q那么就认ؓ(f)存在一?/span> <span lang="EN-US">mobile</span> <span style="FONT-FAMILY: 宋体">的属性,q样可以方便我们?/span> <span lang="EN-US">Bean</span> <span style="FONT-FAMILY: 宋体">c通过一个接口来定义而不用去兛_具体实现Q不用去兛_ </span> <span lang="EN-US">Bean</span> <span style="FONT-FAMILY: 宋体">中数据的存储。比如我们可以把所有的</span> <span lang="EN-US">getter/setter</span> <span style="FONT-FAMILY: 宋体">Ҏ(gu)攑ֈ接口里定义,但是真正数据的存取则是在具体cMd玎ͼq样可提高系l的扩展性?/span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal"> <span style="FONT-FAMILY: 宋体">ȝ</span> </p> <p class="MsoNormal"> <span lang="EN-US"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 宋体">?/span> <span lang="EN-US">Java</span> <span style="FONT-FAMILY: 宋体">的反以?qing)内省应用到E序设计中去可以大大的提供程序的化和可扩展性。有很多目都是采取q两U技术来实现其核心功能,例如我们前面提到?/span> <span lang="EN-US">Struts</span> <span style="FONT-FAMILY: 宋体">Q还有用于处?/span> <span lang="EN-US">XML</span> <span style="FONT-FAMILY: 宋体">文g?/span> <span lang="EN-US">Digester</span> <span style="FONT-FAMILY: 宋体">目Q其实应该说几乎所有的目都或多或的采用q两U技术。在实际应用q程中二者要怺l合方能发挥真正的智能化以及(qing)高度可扩展性?/span> </p> </div> </font> <img src ="http://www.tkk7.com/wiflish/aggbug/101964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2007-03-05 17:40 <a href="http://www.tkk7.com/wiflish/archive/2007/03/05/101964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat配置(提高q行效率)http://www.tkk7.com/wiflish/archive/2007/01/15/93970.html想飞的鱼想飞的鱼Mon, 15 Jan 2007 07:50:00 GMThttp://www.tkk7.com/wiflish/archive/2007/01/15/93970.htmlhttp://www.tkk7.com/wiflish/comments/93970.htmlhttp://www.tkk7.com/wiflish/archive/2007/01/15/93970.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/93970.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/93970.html?CATALINA_HOME%/conf/web.xml中有(以tomcat5.0.28Z)Q?/p>
 1 < servlet >
 2          < servlet-name > jsp </ servlet-name >
 3          < servlet-class > org.apache.jasper.servlet.JspServlet </ servlet-class >
 4          < init-param >
 5              < param-name > fork </ param-name >
 6              < param-value > false </ param-value >
 7          </ init-param >
 8          < init-param >
 9              < param-name > xpoweredBy </ param-name >
10              < param-value > false </ param-value >
11          </ init-param >
12          < load-on-startup > 3 </ load-on-startup >
13      </ servlet >

在该D代码中增加Q?br />
 1<servlet>
 2        <servlet-name>jsp</servlet-name>
 3        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
 4        <init-param>
 5            <param-name>fork</param-name>
 6            <param-value>false</param-value>
 7        </init-param>
 8        <init-param>
 9            <param-name>xpoweredBy</param-name>
10            <param-value>false</param-value>
11        </init-param>
12        <!--增加的初始化参数-->
13        <init-param>
14            <param-name>development</param-name>
15            <param-value>false</param-value>
16        </init-param>
17        <load-on-startup>3</load-on-startup>
18    </servlet>

development参数的说明:(x)
development         Is Jasper used in development mode (will check for JSP modification on every access)?  [true]
该参数默认gؓ(f)trueQ即tomcat?x)对jsp面的每ơ访问都(g)它是否发生了修改;该参数讄为false后,也就是说tomcat不以开发模式运行,即不再检jsp是否发生了修改,q样能提高运行效率?br />如果pȝq行后,偶尔Ҏ(gu)个jsp面q行了修改,只要删除该jsp面?CATALINA_HOME%/work目录中对应的servlet源文件和class文gQ再讉K该jsp面后,tomcat(jsp引擎)׃(x)重新~译该jsp文g?br />

想飞的鱼 2007-01-15 15:50 发表评论
]]>
[转]关于文g下蝲的几个问题ȝhttp://www.tkk7.com/wiflish/archive/2006/12/29/90670.html想飞的鱼想飞的鱼Fri, 29 Dec 2006 02:44:00 GMThttp://www.tkk7.com/wiflish/archive/2006/12/29/90670.htmlhttp://www.tkk7.com/wiflish/comments/90670.htmlhttp://www.tkk7.com/wiflish/archive/2006/12/29/90670.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/90670.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/90670.html转:(x)http://ltc603.javaeye.com/blog/25158

使用servlet来下载文Ӟ其原理非常简单,只要得到文g的输入流Q或相应字节Q,然后写输出流卛_。现其中的几个l节问题展开Q?
1. MIMEcd的设|:(x)
Web 览器?MIME cd来识别非 HTML 文档Qƈ军_如何昄该文档内的数据?
例如EXCEL文g?MIME cd?"application/vnd.ms-excel "。要用servlet 来打开一?EXCEL 文档Q需要将 response 对象?header ?contentType 讄成“application/vnd.ms-excel ”?
response.setContentType(contentType);
2. Content disposition
HTTP response header中的content-disposition 允许 servlet 指定文档表示的信息。用这Uheader Q你可以将文档指定成单独打开Q而不是在览器中打开Q,q可以根据用L(fng)操作来显C?
如果用户要保存文档,你还可以文档一个文件名。这个徏议名UC(x)出现?Save As 对话框的“文件名”栏中。如果没有指定,则对话框中就?x)出?servlet 的名字?
servlet 中,?header 讄成下面这P(x)
response.setHeader("Content-disposition","attachment;filename="+ "Example.xls" );

response.setHeader("Content-Disposition", "inline; filename="fliename)
点击打开?x)在ie中打开?/p>

需要说明的有三点:(x)
Ø 中文文g名需要进行iso8859-1转码方可正确昄Q?
fileName = new String(fileName.getBytes("GBK"),"iso8859-1");
Ø 传递的文g名,需要包含后~名(如果此文件有后缀名)Q否则丢失文件的属性,而不能自行选择相关E序打开?
Ø 有下载前询问Q是打开文gq是保存到计机Q和通过IE览器直接选择相关应用E序插g打开两种方式Q前者如上代码所C,后者如下:(x)
response.setHeader("Content-disposition","filename="+ "Example.xls" );
3. 在研I文件的上传?qing)下载过E中Q有几点体会(x)
E序的I/O操作往往是性能的瓶颈所在,java io定义了两个基本的抽象c?InputStream和OutputStream,对于不同的数据类型比如磁盘,|络又提供了不同的实玎ͼjava.io 也提供了一些缓冲流(BufferedStream)Qɼ盘可以很快的读写一大块的数? 而Java基本的I/OcMơ只能读写一个字?但缓冲流(BufferedStream)可以一ơ读写一Ҏ(gu)据,,~冲?Buffered Stream)大大提高了I/O的性能。所?
Ø块块的读写数据会(x)非常?因此,量大块的读写数?
Ø使用BufferedInputStream和BufferedOutputStream来批处理数据以提高性能
Ø对象的序列化(serialization)非常影响I/O的性能,量用

注:(x)
1、Servlet中输出流的简单处理方法:(x)      

      //得到当前web应用根目录下test.txt文g的实际物理\?
       String path = getServletContext().getRealPath("/test.txt");    

       OutputStream os 
= response.getOutputStream();
       InputStream is 
= new FileInputStream(path);
       
byte[] buff = new byte[1024];
       
int len;
   
while((len = is.read(buff)) !=  -1{
            os.write(buff, 
0, len);
       }

       
       is.close();
       os.close(); 


2、输出流跟PrintWriter out = response.getWriter();不能同时使用?br />



想飞的鱼 2006-12-29 10:44 发表评论
]]>
HTTP响应?/title><link>http://www.tkk7.com/wiflish/archive/2006/11/23/83082.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 23 Nov 2006 09:16:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2006/11/23/83082.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/83082.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2006/11/23/83082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/83082.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/83082.html</trackback:ping><description><![CDATA[止览器缓存当前页面:(x)<br />1、response.setDateHeader("Expires", 0);<br />2、response.setHeader("Cache-Control", "no-cache");<br />3、response.setHeader("Pragma", "no-cache");<br />定时h当前面Q?br />response.setHeader("Refresh", "5");    //每隔5U刷Cơ当前页面?br />定时跌{面<br />response.setHeader("Refresh", "5; URL=http://www.google.com"); //5U后Q当前页面蟩转到google?br /><br /><img src ="http://www.tkk7.com/wiflish/aggbug/83082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2006-11-23 17:16 <a href="http://www.tkk7.com/wiflish/archive/2006/11/23/83082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用jar命o(h)创徏可执行的jar?/title><link>http://www.tkk7.com/wiflish/archive/2006/07/05/56672.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 05 Jul 2006 03:00:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2006/07/05/56672.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/56672.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2006/07/05/56672.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/56672.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/56672.html</trackback:ping><description><![CDATA[ <br />1、创建可执行的jar包?br />手工写manifest.mf文g(jar命o(h)自动生成的MANIFEST.MF文g中不?x)包含Main-Class属?QD例说明:(x)<br />目录l构Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">mymanifest.mf //该文件可以随意放|?只要在执行jar命o(h)时指定mymanifest.mf文g所在位|?</span><br /><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">Test.</span><span style="color: rgb(0, 0, 255);">class</span></div><br />test.Test代码Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test;<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Test {<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">HelloWorld!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);">}</span></div><br />mymanifest.mf文g内容Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Manifest</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Version: </span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性是创徏可执行jar包必需的,指定的Main-Class为全路径cdQ且该类必需有mainҎ(gu)Q?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Main</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Class: test.Test<br />Created</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">By: wiflish</span></div><br />在src目录下执行:(x) <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jar cvfm test.jar ..</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">mymanifest .</span></div>完成后会(x)在src目录下生成一个test.jar文g。由于没有可视化界面Q双击test.jar会(x)看到没反应?br />在命令行执行java -jar test.jar׃(x)得到输出HelloWorld!<br /><br />q时完成了基本的创建可执行的jar包?br /><br />2、创依赖其他包的可执行jar包?br />q时只要更改mymanifest.mf文g加入Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Manifest</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Version: </span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性是创徏可执行jar包必需的,指定的Main-Class为全路径cdQ且该类必需有mainҎ(gu)Q?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Main</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Class: test.Test<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性指定依赖包的\?路径是相对jar包所在\?</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Class</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Path: lib</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">swing</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">layout</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">.jar </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">q里举例说明Q随便用的包</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Created</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">By: wiflish</span></div><br />目录l构Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends.</span><span style="color: rgb(0, 0, 255);">class //假设该类执行依赖?swing-layout-1.0.jarQ具体代码略?/span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">testDepends</span><span style="color: rgb(0, 0, 0);">.jar<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">lib<br />    swing</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">layout</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">.jar</span></div><br />双击<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">testDepends</span><span style="color: rgb(0, 0, 0);">.jarp正确执行Q如?/span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends</span><span style="color: rgb(0, 0, 0);">.jar包所在的当前目录下没有lib/swing-layout-1.0.jar的话Q如下目录结构:(x)<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">假设该类执行依赖于 swing-layout-1.0.jarQ具体代码略?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  testDepends.jar</span><span style="color: rgb(0, 0, 0);"></span></div>双击testDepends.jar,会(x)报Could not find the main class, Program will exit.<br />在命令行执行 java -jar testDepends.jar,׃(x)得到找不到TestDepends.class中所依赖的类的错?<br /></span><br /><br /><img src ="http://www.tkk7.com/wiflish/aggbug/56672.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2006-07-05 11:00 <a href="http://www.tkk7.com/wiflish/archive/2006/07/05/56672.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jar命o(h)中的MANIFEST文g属性列?/title><link>http://www.tkk7.com/wiflish/archive/2006/07/05/56659.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 05 Jul 2006 02:09:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2006/07/05/56659.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/56659.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2006/07/05/56659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/56659.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/56659.html</trackback:ping><description><![CDATA[官方链接Q?a target="_blank" title="JAR File Specification" ><b>JAR File Specification</b></a><br />MANIFEST.MF文g属性:(x)<br /><h3>Main Attributes</h3> Main attributes are the attributes that are present in the main section of the manifest. They fall into the following different groups: <ul><li> general main attributes</li></ul><ul><ul><li> Manifest-Version:</li></ul><ul>Defines the manifest file version. The value is a legitimate version number, as described in the above spec. <br />  <li> Created-By:</li><br />Defines the version and the vendor of the java implementation on top of which this manifest file is generated. This attribute is generated by the <tt>jar</tt> tool. <br />  <li> Signature-Version:</li><br />Defines the signature version of the jar file. The value should be a valid <i>version-number</i> string. <br />  <li> Class-Path :</li><br />The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path. <br /> </ul><li> attribute defined for stand-alone applications</li> This attribute is used by stand-alone applications that are bundled into executable jar files which can be invoked by the java runtime directly by running "<tt>java -jar x.jar</tt>". <ul><li> Main-Class :</li><br />The value of this attribute defines the relative path of the main application class which the launcher will load at startup time. The value must <em>not</em> have the <tt>.class</tt> extension appended to the class name.</ul></ul><ul><li> attributes defined for applets</li> These attributes is used by an applet which is bundled into JAR files to define requirements, version and location information for the extensions which this applet depends on. (see  <a >Extension Versioning</a> ).  <ul><li> Extension-List:</li><br />This attribute indicates the extensions that are needed by the applet. Each extension listed in this attribute will have a set of additional attributes that the applet uses to specify which version and vendor of the extension it requires. <br />  <li> <extension>-Extension-Name :</li><br />This attribute is the unique name of the extension. The Java Plug-in will compare the value of this attribute with the Extension-Name attribute in the manifests of installed extensions to determine if the extension is installed. <br />  <li> <extension>-Specification-Version</li><br />This attribute specifies the minimum extension specification version that is required by the applet. The Java Plug-in will compare the value of this attribute with the Specification-Version attribute of the installed extension to determine if the extension is up to date. <br />  <li> <extension>-Implementation-Version</li><br />This attritute specifies the minimum extension implementation version number that is required by the applet. The Java Plug-in will compare the value of this attribute with the Implementation-Version attribute of the installed extension to see if a more recent implementation needs to be downloaded. <br />  <li> <extension>-Implementation-Vendor-Id</li><br />This attribute can be used to identify the vendor of an extension implementation if the applet requires an implementation from a specific vendor. The Java Plug-in will compare the value of this attribute with the Implementation-Vendor-Id attribute of the installed extension. <br />  <li> <extension>-Implementation-URL</li><br />This attribute specifies a URL that can be used to obtain the most recent version of the extension if the required version is not already installed. <br /> </ul><li> attribute defined for extension identification</li> This attribute is used by extensions to define their unique identity. <ul><li> Extension-Name:</li> This attribute specifies a name for the extension contained in the Jar file. The name should be a unique identifier such as the name of the main package comprising the extension.</ul>   <li> attributes defined for extension and  package <a >versioning</a>  and <a >sealing</a> information</li> These attributes define features of the extension which the JAR file is a part of. The value of these attributes apply to all the packages in the JAR file, but can be overridden by per-entry attributes.  <ul><li> Implementation-Title :</li> The value is a string that defines the title of the extension implementation.  <li> Implementation-Version :</li><br />The value is a string that defines the version of the extension implementation. <br />  <li> Implementation-Vendor :</li><br />The value is a string that defines the organization that maintains the extension implementation. <br />  <li> Implementation-Vendor-Id :</li><br />The value is a string id that uniquely defines the organization that maintains the  extension implementation. <br />  <li> Implementation-URL :</li><br />This attribute defines the URL from which the extension implementation can be downloaded from. <br />  <li>  Specification-Title :</li><br />The value is a string that defines the title of the extension specification. <br />  <li> Specification-Version :</li><br />The value is a string that defines the version of the extension specification. <br />  <li> Specification-Vendor :</li><br />The value is a string that defines the organization that maintains the extension specification.</ul></ul><ul><ul><li> Sealed :</li><br />This attribute defines whether this JAR file is sealed or not. The value can be either "true" or "false", case is ignored. If it is set to "true", then all the packages in the JAR file are defaulted to be sealed, unless they are defined otherwise individually.</ul></ul><br /><img src ="http://www.tkk7.com/wiflish/aggbug/56659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2006-07-05 10:09 <a href="http://www.tkk7.com/wiflish/archive/2006/07/05/56659.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过java获取pȝ环境变量http://www.tkk7.com/wiflish/archive/2006/07/03/56384.html想飞的鱼想飞的鱼Mon, 03 Jul 2006 09:11:00 GMThttp://www.tkk7.com/wiflish/archive/2006/07/03/56384.htmlhttp://www.tkk7.com/wiflish/comments/56384.htmlhttp://www.tkk7.com/wiflish/archive/2006/07/03/56384.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/56384.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/56384.html
 1     public static Map getEnv() {
 2         Map map = new HashMap();
 3         String OS = System.getProperty("os.name").toLowerCase();
 4         
 5         Process p = null;
 6         
 7         /**
 8          * 以windowsZ.
 9          */
10         if(OS.indexOf("windows"> -1) {
11             try {
12                 p = Runtime.getRuntime().exec("cmd /c set");
13                 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
14                 
15                 String line;
16                 
17                 while((line = br.readLine()) != null) {
18                     String[] str = line.split("=");
19                     map.put(str[0], str[1]);
20                 }
21             } catch(IOException ioe) {
22                 ioe.printStackTrace();
23             }
24         }
25         return map;
26     }

上述代码windowspȝ中的环境变量转换为java的MapQ只要通过map.get(key)p得到环境变量|比如map.get("JAVA_HOME")Q得到JAVA_HOME的|即JAVA_HOME的系l\径?br />
值得注意的是在java中用windows操作pȝ命o(h)时要在命令前?u> cmd /cQ否则java?x)报?),错误列表如下Q?br />
 1 java.io.IOException: CreateProcess: ${执行的操作命令表辑ּ或?bat文g} error=2
 2 at java.lang.Win32Process.create(Native Method)
 3 at java.lang.Win32Process.<init>(Win32Process.java:63)
 4 at java.lang.Runtime.execInternal(Native Method)
 5 at java.lang.Runtime.exec(Runtime.java:566)
 6 at java.lang.Runtime.exec(Runtime.java:428)
 7 at java.lang.Runtime.exec(Runtime.java:364)
 8 at java.lang.Runtime.exec(Runtime.java:326)
 9 at org.apache.jsp.ChangeDirBajaRCXX_jsp._jspService(ChangeDirBaja
10 p.java:185)

该错误的解释Q?br />
The error 2 comes from the CreateProcess() call, from MSDN (GetLastError():

2 - The system cannot find the file specified. - ERROR_FILE_NOT_FOUND

So, it means the path you passed cannot be found. Maybe you did not configure your Runtime 
class correctly.
put the batch file in the same directory as the 
class file and use (for a test):



想飞的鱼 2006-07-03 17:11 发表评论
]]>
[转]java基本c装入异?/title><link>http://www.tkk7.com/wiflish/archive/2006/05/24/47837.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 24 May 2006 08:24:00 GMT</pubDate><guid>http://www.tkk7.com/wiflish/archive/2006/05/24/47837.html</guid><wfw:comment>http://www.tkk7.com/wiflish/comments/47837.html</wfw:comment><comments>http://www.tkk7.com/wiflish/archive/2006/05/24/47837.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/wiflish/comments/commentRss/47837.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/wiflish/services/trackbacks/47837.html</trackback:ping><description><![CDATA[ <p> <a target="_blank" class="" title="" name="1">原文链接Qhttp://www-128.ibm.com/developerworks/cn/java/j-dclp2.html<span id="ldzpulv" class="atitle"></span></a> </p> <p> <a name="1"> <span id="rjotsav" class="atitle"> </span> </a> </p> <br /> <p> <a name="1"> <span id="valyekm" class="atitle">ClassNotFoundException</span> </a> </p> <p> <code>ClassNotFoundException</code> 是最常见的类装入异常cd。它发生在装入阶Dc(din)Java 规范?<code>ClassNotFoundException</code> 的描q是q样的:(x)</p> <p> 当应用程序试N过cȝ字符串名Uͼ使用以下三种Ҏ(gu)装入c,但却找不到指定名U的cd义时抛出该异常?/p> <ul> <li>c?<code>Class</code> 中的 <code>forName()</code> Ҏ(gu)?/li> <li>c?<code>ClassLoader</code> 中的 <code>findSystemClass()</code> Ҏ(gu)?/li> <li>c?<code>ClassLoader</code> 中的 <code>loadClass()</code> Ҏ(gu)?/li> </ul> <p>所以,如果昑ּ地装入类的尝试失败,那么抛?<code>ClassNotFoundException</code>。清?1 中的试用例提供的示例代码抛Z一?<code>ClassNotFoundException</code>Q?/p> <br /> <a name="N100CC"> <b>清单 1. ClassNotFoundExceptionTest.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />import java.net.MalformedURLException;<br />import java.net.URL;<br />import java.net.URLClassLoader;<br /><br />public class ClassNotFoundExceptionTest {<br /><br /> public static void main(String args[]) {<br /> try {<br /> URLClassLoader loader = new URLClassLoader(new URL[] { new URL(<br /> "file://C:/CL_Article/ClassNotFoundException/")});<br /> loader.loadClass("DoesNotExist");<br /> } catch (ClassNotFoundException e) {<br /> e.printStackTrace();<br /> } catch (MalformedURLException e) {<br /> e.printStackTrace();<br /> }<br /> }<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>q个试用例定义了一个类装入器(<code>MyClassLoader</code>Q,用于装入一个不存在的类Q?code>DoesNotExist</code>Q。当它运行时Q会(x)出现以下异常Q?/p> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br />java.lang.ClassNotFoundException: DoesNotExist<br /> at java.net.URLClassLoader.findClass(URLClassLoader.java:376)<br /> at java.lang.ClassLoader.loadClass(ClassLoader.java:572)<br /> at java.lang.ClassLoader.loadClass(ClassLoader.java:504)<br /> at ClassNotFoundExceptionTest.main(ClassNotFoundExceptionTest.java:11)</code> </pre> </td> </tr> </tbody> </table> <br /> <p>因ؓ(f)q个试试图使用?<code>loadClass()</code> 的显式调用来q行装入Q所以抛?<code>ClassNotFoundException</code>?/p> <p>通过抛出 <code>ClassNotFoundException</code>Q类装入器提C,定义cL所需要的字节码在c装入器所查找的位|上不存在。这些异怿复v来通常比较单。可以用 IBM ?verbose 选项(g)查类路径Q确保用的c\径设|正(要获?verbose 的更多信息,请参阅本pd?<a >W一文?/a>Q。如果类路径讄正确Q但是仍然看到这个错误,那么是需要的cdc\径中不存在。要修复q个问题Q可以把cȝ动到c\径中指定的目录或 JAR 文g中,或者把cL在的位置d到类路径中?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="2"> <span id="inkddjp" class="atitle">NoClassDefFoundError</span> </a> </p> <p> <code>NoClassDefFoundError</code> 是类装入器在装入阶段抛出的另一个常见异常。JVM 规范?<code>NoClassDefFoundError</code> 的定义如下:(x)</p> <blockquote> 如果 Java 虚拟机或 <code>ClassLoader</code> 实例试图装入cd义(作ؓ(f)正常的方法调用的一部分Q或者作Z?new 表达式创建新实例的一部分Q,但却没有扑ֈcd义时抛出该异常? <br /><br /> 当目前执行的cdl编译,但是找不到它的定义时Q会(x)存在 searched-for cd义? </blockquote> <p>实际上,q意味着 <code>NoClassDefFoundError</code> 的抛出,是不成功的隐式类装入的结果?/p> <p>清单 2 到清?4 的测试用例生了 <code>NoClassDefFoundError</code>Q因为类 <code>B</code> 的隐式装入会(x)p|Q?/p> <br /> <a name="N1012A"> <b>清单 2. NoClassDefFoundErrorTest.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class NoClassDefFoundErrorTest {<br /> public static void main(String[] args) {<br /> A a = new A();<br /> }<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <br /> <a name="N10134"> <b>清单 3. A.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class A extends B {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <br /> <a name="N1013E"> <b>清单 4. B.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class B {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>q几个清单中的代码编译好之后Q删?<code>B</code> 的类文g。当代码执行Ӟ׃(x)出现以下错误Q?/p> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br />Exception in thread "main" java.lang.NoClassDefFoundError: B<br /> at java.lang.ClassLoader.defineClass0(Native Method)<br /> at java.lang.ClassLoader.defineClass(ClassLoader.java:810)<br /> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:147)<br /> at java.net.URLClassLoader.defineClass(URLClassLoader.java:475)<br /> at java.net.URLClassLoader.access$500(URLClassLoader.java:109)<br /> at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:848)<br /> at java.security.AccessController.doPrivileged1(Native Method)<br /> at java.security.AccessController.doPrivileged(AccessController.java:389)<br /> at java.net.URLClassLoader.findClass(URLClassLoader.java:371)<br /> at java.lang.ClassLoader.loadClass(ClassLoader.java:572)<br /> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)<br /> at java.lang.ClassLoader.loadClass(ClassLoader.java:504)<br /> at NoClassDefFoundErrorTest.main(NoClassDefFoundErrorTest.java:3)<br /></code> </pre> </td> </tr> </tbody> </table> <br /> <p>c?<code>A</code> 扩展了类 <code>B</code>Q所以,当类 <code>A</code> 装入Ӟc装入器?x)隐式地装入c?<code>B</code>。因为类 <code>B</code> 不存在,所以抛?<code>NoClassDefFoundError</code>。如果显式地告诉c装入器装入c?<code>B</code>Q例如通过 <code>loadClass("B")</code> 调用Q,那么׃(x)抛出 <code>ClassNotFoundException</code>?/p> <p>昄Q要修复q个Ҏ(gu)CZ中的问题Q在对应的类装入器的c\径中Q必d在类 <code>B</code>。这个示例看h可能价g大、也不真实,但是Q在复杂的有许多cȝ真实pȝ中,?x)因为类在打包或部v期间的遗p发生这cLc(din)?/p> <p>在这个例子中Q?code>A</code> 扩展?<code>B</code>Q但是,即 <code>A</code> 用其他方式引?<code>B</code>Q也?x)出现同L(fng)问题 —?例如Q以Ҏ(gu)参数引用或作为实例字Dc(din)如果两个类之间的关pL引用关系而不是承关p,那么?x)在W一ơ?<code>A</code> 时抛出错误,而不是在装入 <code>A</code> 时抛出?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="3"> <span id="xsrdprx" class="atitle">ClassCastException</span> </a> </p> <p>c装入器能够抛出的另一个异常是 <code>ClassCastException</code>。它是在cd比较中发C兼容cd的时候抛出的。JVM 规范指定 <code>ClassCastException</code> 是:(x)</p> <blockquote> 该异常的抛出Q表明代码企图把对象的类型{换成一个子c,而该对象q不是这个子cȝ实例? </blockquote> <p>清单 5 演示的代码示例会(x)产生一?<code>ClassCastException</code>Q?/p> <br /> <a name="N101B8"> <b>清单 5. ClassCastException.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class ClassCastExceptionTest {<br /> public ClassCastExceptionTest() {<br /> }<br /><br /> private static void storeItem(Integer[] a, int i, Object item) {<br /> a[i] = (Integer) item;<br /> }<br /><br /> public static void main(String args[]) {<br /> Integer[] a = new Integer[3];<br /> try {<br /> storeItem(a, 2, new String("abc"));<br /> } catch (ClassCastException e) { <br /> e.printStackTrace();<br /> }<br /> }<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>在清?5 中,调用?<code>storeItem()</code> Ҏ(gu)Q用一?<code>Integer</code> 数组、一?<code>int</code> 和一个字W串作ؓ(f)参数。但是在内部Q该Ҏ(gu)做了两g事:(x)</p> <ul> <li>隐式地把 <code>String</code> 对象cd转换?<code>Object</code> cdQ用于参数列表)?/li> <li>昑ּ地把q个 <code>Object</code> cd转换?<code>Integer</code> cdQ在Ҏ(gu)定义中)?/li> </ul> <p>当程序运行时Q会(x)出现以下异常Q?/p> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br />java.lang.ClassCastException: java.lang.String<br /> at ClassCastExceptionTest.storeItem(ClassCastExceptionTest.java:6)<br /> at ClassCastExceptionTest.main(ClassCastExceptionTest.java:12)</code> </pre> </td> </tr> </tbody> </table> <br /> <p>q个异常是由昑ּcd转换抛出的,因ؓ(f)试用例试图把类型ؓ(f) <code>String</code> 的东西{换成 <code>Integer</code>?/p> <p>当检查对象(例如清单 5 中的 <code>item</code>Qƈ把类型{换成目标c(<code>Integer</code>Q时Q类装入器会(x)(g)查以下规则:(x)</p> <ul> <li> <b>对于普通对象(非数l)Q?/b>对象必须是目标类的实例或目标cȝ子类的实例。如果目标类是接口,那么?x)把它当作实C该接口的一个子cR?br /><br /></li> <li> <b>对于数组cdQ?/b>目标cdL数组cd?<code>java.lang.Object</code>?code>java.lang.Cloneable</code> ?<code>java.io.Serializable</code>?/li> </ul> <p>如果q反了以上Q何一条规则,那么c装入器׃(x)抛出 <code>ClassCastException</code>。修复这cd常的最单方式就是仔l检查对象要转换到的cd是否W合以上提到的规则。在某些情况下,在做cd转换之前?<code>instanceof</code> q行(g)查是有意义的?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="4"> <span id="kqvaxsf" class="atitle">UnsatisfiedLinkError</span> </a> </p> <p>在把本机调用链接到对应的本机定义Ӟc装入器扮演着重要角色。如果程序试图装入一个不存在或者放错的本机库时Q在链接阶段的解析过E会(x)发生 <code>UnsatisfiedLinkError</code>。JVM 规范指定 <code>UnsatisfiedLinkError</code> 是:(x)</p> <blockquote> 对于声明?<code>native</code> 的方法,如果 Java 虚拟机找不到和它对应的本a定义Q就?x)抛异常? </blockquote> <p>当调用本机方法时Q类装入器会(x)试装入定义了该Ҏ(gu)的本机库。如果找不到q个库,׃(x)抛出q个错误?/p> <p>清单 6 演示了抛?<code>UnsatisfiedLinkError</code> 的测试用?Q?/p> <br /> <a name="listing6"> <b>清单 6. UnsatisfiedLinkError.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class UnsatisfiedLinkErrorTest {<br /><br /> public native void call_A_Native_Method();<br /><br /> static {<br /> System.loadLibrary("myNativeLibrary");<br /> }<br /><br /> public static void main(String[] args) {<br /> new UnsatisfiedLinkErrorTest().call_A_Native_Method();<br /> }<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>q段代码调用本机Ҏ(gu) <code>call_A_Native_Method()</code>Q该Ҏ(gu)是在本机?<code>myNativeLibrary</code> 中定义的。因个库不存在,所以在E序q行时会(x)发生以下错误Q?/p> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br />The java class could not be loaded. java.lang.UnsatisfiedLinkError:<br /> Can't find library myNativeLibrary (myNativeLibrary.dll)<br /> in sun.boot.library.path or java.library.path<br />sun.boot.library.path=D:\sdk\jre\bin<br />java.library.path= D:\sdk\jre\bin<br /><br />at java.lang.ClassLoader$NativeLibrary.load(Native Method)<br /> at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2147)<br /> at java.lang.ClassLoader.loadLibrary(ClassLoader.java:2006)<br /> at java.lang.Runtime.loadLibrary0(Runtime.java:824)<br /> at java.lang.System.loadLibrary(System.java:908)<br /> at UnsatisfiedLinkErrorTest.<clinit>(UnsatisfiedLinkErrorTest.java:6)<br /></code> </pre> </td> </tr> </tbody> </table> <br /> <p>本机库的装入p?<code>System.loadLibrary()</code> Ҏ(gu)的类的类装入器启?—?在清?6 中,是 <code>UnsatisfiedLinkErrorTest</code> 的类装入器。根据用的c装入器Q会(x)搜烦不同的位|:(x)</p> <ul> <li>对于?bootstrap c装入器装入的类Q搜?<code>sun.boot.library.path</code>?/li> <li>对于由扩展类装入器装入的c,先搜?<code>java.ext.dirs</code>Q然后是 <code>sun.boot.library.path</code>Q然后是 <code>java.library.path</code>?/li> <li>对于ql类装入器装入的c,搜烦 <code>sun.boot.library.path</code>Q然后是 <code>java.library.path</code>?/li> </ul> <p>在清?6 中,<code>UnsatisfiedLinkErrorTest</code> cLql类装入器装入的。要装入所引用的本机库Q这个类装入器先查找 <code>sun.boot.library.path</code>Q然后查?<code>java.library.path</code>。因为在两个位置中都没有需要的库,所以类装入器抛?<code>UnsatisfiedLinkageError</code>?/p> <p>一旦理解了库装入过E所涉及(qing)的类装入器,可以通过把库攑֜合适位|来解决q类问题?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="5"> <span id="obnheke" class="atitle">ClassCircularityError</span> </a> </p> <p>JVM 规范指定 <code>ClassCircularityError</code> 的抛出条件是Q?/p> <blockquote> cL接口׃是自q类或超接口而不能被装入? </blockquote> <p>q个错误是在链接阶段的解析过E中抛出的。这个错误有点奇怪,因ؓ(f) Java ~译器不允许发生q种循环情况。但是,如果独立地编译类Q然后再把它们放在一P可能发生这个错误。请设想以下场景。首先,~译清单 7 和清?8 中的c:(x)</p> <br /> <a name="listing7"> <b>清单 7. A.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class A extends B {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <br /> <a name="N102D0"> <b>清单 8. B.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class B {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>然后Q分别编译清?9 和清?10 中的c:(x)</p> <br /> <a name="listing9"> <b>清单 9. A.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class A {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <br /> <a name="listing10"> <b>清单 10. B.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class B extends A {<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>最后,采用清单 7 的类 <code>A</code> 和清?10 的类 <code>B</code>Qƈq行一个应用程序,试图装入 <code>A</code> 或?<code>B</code>。这个情늜h可能不太可能Q但是在复杂的系l中Q在把不同部分放在一L(fng)时候,可能?x)发生类似的情况?/p> <p>昄Q要修复q个问题Q必避免@环的cdơ结构?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="6"> <span id="mzejsxo" class="atitle">ClassFormatError</span> </a> </p> <p>JVM 规范指出Q抛?<code>ClassFormatError</code> 的条件是Q?/p> <blockquote> 负责指定所h的编译类或接口的二进制数据Ş式有误? </blockquote> <p>q个异常是在c装入的链接阶段的校验过E中抛出。如果字节码发生了更改,例如ȝ本号或次版本号发生了更改Q那么二q制数据的Ş式就?x)有误。例如,如果对字节码故意做了更改Q或者在通过|络传送类文g时现Z错误Q那么就可能发生q个异常?/p> <p>修复q个问题的惟一Ҏ(gu)是获得字节码的正确副本Q可能需要重新进行编译?/p> <br /> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td> <img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" /> <br /> <img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" /> </td> </tr> </tbody> </table> <table class="no-print" align="right" cellpadding="0" cellspacing="0"> <tbody> <tr align="right"> <td> <img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" /> <br /> <br /> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="7"> <span id="dcseuse" class="atitle">ExceptionInInitializerError</span> </a> </p> <p>Ҏ(gu) JVM 规范Q抛?<code>ExceptionInInitializer</code> 的情冉|Q?/p> <ul> <li>如果初始化器H然完成Q抛Z些异?<code>E</code>Q而且 <code>E</code> 的类不是 <code>Error</code> 或者它的某个子c,那么׃(x)创徏 <code>ExceptionInInitializerError</code> cȝ一个新实例Qƈ?<code>E</code> 作ؓ(f)参数Q用q个实例代替 <code>E</code>?br /><br /></li> <li>如果 Java 虚拟囑ֈ建类 <code>ExceptionInInitializerError</code> 的新实例Q但是因为出?<code>Out-Of-Memory-Error</code> 而无法创建新实例Q那么就抛出 <code>OutOfMemoryError</code> 对象作ؓ(f)代替?/li> </ul> <p>清单 8 中的代码抛出 <code>ExceptionInInitializerError</code>Q?/p> <br /> <a name="listing8"> <b>清单 8. ExceptionInInitializerErrorTest.java</b> </a> <br /> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br /> <br />public class ExceptionInInitializerErrorTest {<br /> public static void main(String[] args) {<br /> A a = new A();<br /> }<br />}<br /><br />class A {<br /> // If the SecurityManager is not turned on, a <br /> // java.lang.ExceptionInInitializerError will be thrown <br /> static {<br /> if(System.getSecurityManager() == null)<br /> throw new SecurityException();<br /> }<br />}</code> </pre> </td> </tr> </tbody> </table> <br /> <p>当静态代码块中发生异常时Q会(x)被自动捕捉ƈ?<code>ExceptionInInitializerError</code> 包装该异常。在下面的输Z可以看到q点Q?/p> <table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%"> <tbody> <tr> <td> <pre> <code class="section"> <br />Exception in thread "main" java.lang.ExceptionInInitializerError<br /> at ExceptionInInitializerErrorTest.main(ExceptionInInitializerErrorTest.java:3)<br />Caused by: java.lang.SecurityException<br /> at A.<clinit>(ExceptionInInitializerErrorTest.java:12)<br /> ... 1 more</code> </pre> </td> </tr> </tbody> </table> <br /> <p>q个错误在类装入的初始化阶段抛出。修复这个错误的Ҏ(gu)是检查造成 <code>ExceptionInInitializerError</code> 的异常(在堆栈跟t的 <code>Caused by:</code> 下显C)q寻N止抛个异常的方式?/p> <img src ="http://www.tkk7.com/wiflish/aggbug/47837.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/wiflish/" target="_blank">想飞的鱼</a> 2006-05-24 16:24 <a href="http://www.tkk7.com/wiflish/archive/2006/05/24/47837.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google Web Toolkithttp://www.tkk7.com/wiflish/archive/2006/05/22/47455.html想飞的鱼想飞的鱼Mon, 22 May 2006 06:12:00 GMThttp://www.tkk7.com/wiflish/archive/2006/05/22/47455.htmlhttp://www.tkk7.com/wiflish/comments/47455.htmlhttp://www.tkk7.com/wiflish/archive/2006/05/22/47455.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/47455.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/47455.htmlGoogle Web Toolkit (GWT) is a Java software development framework that makes writing AJAX applications like Google Maps and Gmail easy for developers who don't speak browser quirks as a second language. Writing dynamic web applications today is a tedious and error-prone process; you spend 90% of your time working around subtle incompatabilities between web browsers and platforms, and JavaScript's lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile.

GWT lets you avoid many of these headaches while offering your users the same dynamic, standards-compliant experience. You write your front end in the Java programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.

GWT website: http://code.google.com/webtoolkit/



想飞的鱼 2006-05-22 14:12 发表评论
]]>
ant中宏定义例子http://www.tkk7.com/wiflish/archive/2006/05/18/46856.html想飞的鱼想飞的鱼Thu, 18 May 2006 08:47:00 GMThttp://www.tkk7.com/wiflish/archive/2006/05/18/46856.htmlhttp://www.tkk7.com/wiflish/comments/46856.htmlhttp://www.tkk7.com/wiflish/archive/2006/05/18/46856.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/46856.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/46856.html 一个ant中用于编译的宏定义例子:(x)
 1
     <macrodef name="compile">
 2         <attribute name="module"/>
 3         <attribute name="additional.src.dirs" default=""/>
 4         <element name="options" optional="yes"/>
 5 
 6         <sequential>
 7             <echo>Compiling @{module}</echo>
 8             <mkdir dir="${build.dir}/@{module}/classes"/>
 9             <mkdir dir="${test.dir}/@{module}/classes"/>
10             <javac srcdir="${src}/@{module};@{additional.src.dirs}"
11                 destdir="${build.dir}/@{module}/classes" debug="${compile.debug}"
12                 deprecation="${compile.deprecation}" optimize="${compile.optimize}"
13                 classpathref="@{module}.compile.classpath">
14                 <options/>
15             </javac>
16             <javac srcdir="test/@{module}" debug="true"
17                 destdir="${test.dir}/@{module}/classes">
18                 <classpath>
19                     <path refid="@{module}.test.classpath"/>
20                     <path location="${build.dir}/@{module}/classes"/>
21                 </classpath>
22                 <options/>
23             </javac>
24         </sequential>
25     </macrodef>

   调用宏代码:(x) 
1?/span><compile module="web" additional.src.dirs="${build.dir}/web/gen"/>
2?lt;compile module="dao"/>


想飞的鱼 2006-05-18 16:47 发表评论
]]>
ant property标签_解http://www.tkk7.com/wiflish/archive/2006/05/12/45814.html想飞的鱼想飞的鱼Fri, 12 May 2006 03:49:00 GMThttp://www.tkk7.com/wiflish/archive/2006/05/12/45814.htmlhttp://www.tkk7.com/wiflish/comments/45814.htmlhttp://www.tkk7.com/wiflish/archive/2006/05/12/45814.html#Feedback0http://www.tkk7.com/wiflish/comments/commentRss/45814.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/45814.html Property讄属性的7U方法:(x)

1、设|name和value属性|比如Q?lt;property name="srcdir" value="${basedir}/src"/>
2、设|name和refid属性|比如Q?lt;property name="srcpath" refid="dao.compile.classpath"/>Q其中  ?dao.compile.classpath在别的地方定义?br />3、设|name和location属性|比如Q?lt;property name="srcdir" location="src"/>Q即srcdir的D    |ؓ(f)Q当前项目根目录?src目录?br />4、设|file属性|比如Q?lt;property file="build.properties"/>Q?导入build.properties属性文件中    的属性?br />5、设|resource属性|比如Q?lt;propety resource="build.properties"/>,导入build.properties属性文    件中的属性?br />6、设|url属性|比如Q?lt;property url="http://www.tkk7.com/wiflish/build.properties"/>,导  ?入http://www.tkk7.com/wiflish/build.properties属性文件中的属性倹{?br />7、设|环境变量,比如Q?lt;property environment="env"/>Q设|系l的环境变量为前~env.
     <property name="tomcat.home" value="${env.CATALINA_HOME}"/> 系l的tomcat安装目录讄刊W ?tomcat.home属性中?br />

想飞的鱼 2006-05-12 11:49 发表评论
]]>
Xdoclet的标{֏(qing)用法http://www.tkk7.com/wiflish/archive/2006/05/11/45626.html想飞的鱼想飞的鱼Thu, 11 May 2006 03:43:00 GMThttp://www.tkk7.com/wiflish/archive/2006/05/11/45626.htmlhttp://www.tkk7.com/wiflish/comments/45626.htmlhttp://www.tkk7.com/wiflish/archive/2006/05/11/45626.html#Feedback2http://www.tkk7.com/wiflish/comments/commentRss/45626.htmlhttp://www.tkk7.com/wiflish/services/trackbacks/45626.htmlXdoclet的标{֏(qing)用法


想飞的鱼 2006-05-11 11:43 发表评论
]]>
վ֩ģ壺 ŷպþAV| ŷղwww| ɫ͵͵ɫݺ99| պƷרҹ | ޾ƷƵ| ŮƵվ| Ʒ鶹ѹۿ| ұͨӰƬ߲ | ѿjŽŮjѿ| ߹ۿƵѹ| ƵƷ| Ʒ͵Ƶѹۿ| ŮſȸͰƵ | þþþѿAƬAPP| ޾ƷԴ26u| vպv| 99þþùƷ޿| þñѵӰˬˬˬ| ɫݺɫۺƵ | þ޾Ʒ벥| avרҳ| ߿vַ| AVպAV߳ר| Ƶ97| ߹ۿëƬ| ޹˱ɫ| þһѵ| þþ뾫ƷպĦ| | ˳ӰԺۿ| ˾ƷƵ| ½һëƬƵۿi| С˵ͼƬ| Ʒþ| ɫ͵͵͵վɫ͵һ| jŮjڲվ | ĻۺϾþۺ| ѻɫַվ| ޼Ůۺ99| ֳִִƵ | ҹ븣Ƶ|