只需要在特定目錄添加一個文件:jaxp.properties
內容如下
javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
如果是Bea/jrockit可以添加到如下類似目錄
D:\bea\jrockit_160_05\jre\lib
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
在Context Path(option):中輸入/Pet
XML Configration file URL中要指定一個.xml文件,比如我們在F:\下建立一個Pet.xml文件,內容如下:
<Context reloadable="false" />docBase不用寫了,因為在下一個文本框中填入。或者更簡單點,這個文本框什么都不填。
在WAR or Directory URL:中鍵入F:\PetWet或者F:\Pet.war都可以,然后點擊Deploy按鈕,看看上面是不是已經看到了你web應用程序,名字就是你Context Path(option):中的名字。
如果你部署.war文件還有更加簡單的方式,下面還有個Select WAR file uploae點擊瀏覽選擇.war文件,然后點擊Deploy也可以。
????? Myeclipse:這個是最強大的Eclipse插件,差不多什么都有,是一個一站式的解決插件。
????? WTP(Web Tools Platform):是由Eclipse自己開發的插件。
????? TomcatPlugin(sysdeo):最老牌的Tomcat插件,也是最好用的。
?
個人Blog:? http://www.aygfsteel.com/itspy
插件的適應環境:
???如果沒有特別的原因,應該盡量選擇TomcatPlugin(sysdeo)。
?個人Blog:? http://www.aygfsteel.com/itspy
我查看了幾個例子,它們實現InvocationHandler這個接口時,都通過構造函數傳遞進去了,實際被代理的對象,然后在實現的方法中通過method.invoke(obj,args);obj為構造函數傳遞進來的對象.
比如下面的例子:
public class Handler implements InvocationHandler {
?MethodInterface delegate;
?public Handler(MethodInterface delegate) {
??this.delegate = delegate;
?}
?public Object invoke(Object proxy, Method method, Object[] args)
???throws Throwable {
??if (method.getName().equals("say")) {
???System.out.print("I have get it");
??}
??return method.invoke(this.delegate, args);?
?}
}
函數invoke()傳遞進去的第一個參數proxy就沒有被使用到,但同樣實現了動態代理的效果,后面參考文獻中的例子也是的,難道是這第一個參數就是多余的,如果是這樣的話,就是Sun設置失誤了 ^__^.
sun的文檔是這樣解釋這個參數的:proxy - the proxy instance that the method was invoked on.但這個參數有什么用的,如果不傳遞他進來,會有什么不便呢.
有沒有人能明白這是怎么回事,或者是寫個示例代碼,講講這個第一個參數是干嘛用的?
?
?
注:附兩個完整的動態代理的例子
http://blog.csdn.net/hsyj_0001/archive/2006/04/02/647488.aspx
http://www.java2s.com/Code/Java/Development-Class/Demonstratesadynamicproxy.htm
?有一根27厘米的細木桿,在第3厘米、7厘米、11厘米、17厘米、23厘米這五個位置上各有一只螞蟻。 木桿很細,不能同時通過一只螞蟻。開始 時,螞蟻的頭朝左還是朝右是任意的,它們只會朝前走或調頭, 但不會后退。當任意兩只螞蟻碰頭時,兩只螞蟻會同時調頭朝反方向走。假設螞蟻們每秒鐘可以走一厘米的距離。 編寫程序,求所有螞蟻都離開木桿 的最小時間和最大時間。
看了這個題目之后,突然很感興趣,今天搞了半天把它做出來了,大概花了1個半小時.大公司的題目真是考人.反正都已經用算法實現了,我就不多說了,大家看代碼吧.代碼里面注釋我也盡量全寫了.一共有兩個類,一個是Ant的模型,一個是控制類.原代碼,大家可以在這取得:
http://www.aygfsteel.com/Files/itspy/baidu.rar
//////////////////////////////////////
/*百度面試題
?* 有一根27厘米的細木桿,在第3厘米、7厘米、11厘米、17厘米、23厘米這五個位置上各有一只螞蟻。
?* 木桿很細,不能同時通過一只螞蟻。開始 時,螞蟻的頭朝左還是朝右是任意的,它們只會朝前走或調頭,
?* 但不會后退。當任意兩只螞蟻碰頭時,兩只螞蟻會同時調頭朝反方向走。假設螞蟻們每秒鐘可以走一厘米的距離。
?* 編寫程序,求所有螞蟻都離開木桿 的最小時間和最大時間。
?*
?*
?* 分析:題目中的螞蟻只可能相遇在整數點,不可以相遇在其它點,比如3.5cm處之類的,也就是可以讓每只螞蟻走 1秒,然后
?* 查看是否有相遇的即可.
?*
?* 這樣我的程序實現思路就是,初始化5只螞蟻,讓每只螞蟻走1秒,然后看是否有相遇的,如果有則做相應處理.當每只螞蟻都
?* 走出木桿時,我就記錄當前時間.這樣就可以得到當前狀態情況下,需要多久可以走出木桿,然后遍歷所有狀態則可以得到所胡
?* 可能.
?*/
package baidu;
public class Ant {
?/*
? * step 表示螞蟻每一個單位時間所走的長度
? */
?private final static int step = 1;
?/*
? * position表示螞蟻所處的初始位置
? */
?private int position;
?/*
? * direction表示螞蟻的前進方向,如果為1表示向27厘米的方向走, 如果為-1,則表示往0的方向走。
? */
?private int direction = 1;
?/*
? * 此函數運行一次,表示螞蟻前進一個單位時間,如果已經走下木桿則會拋出異常
? */
?public void walk() {
??if (isOut()) {
???throw new RuntimeException("the ant is out");
??}
??position = position + this.direction * step;
?};
?/**
? * 檢查螞蟻是否已經走出木桿,如果走出返回true
? *
? */
?public boolean isOut() {
??return position <= 0 || position >= 27;
?}
?/**
? * 檢查此螞蟻是否已經遇到另外一只螞蟻
? * @param ant
? * @return 如果遇到返回true
? */
?public boolean isEncounter(Ant ant) {
??return ant.position == this.position;
?}
?/**
? * 改變螞蟻的前進方向
? */
?public void changeDistation() {
??direction = -1 * direction;
?}
?/**
? * 構造函數,設置螞蟻的初始前進方向,和初始位置
? * @param position
? * @param direction
? */
?public Ant(int position, int direction) {
??this.position = position;
??if (direction != 1) {
???this.direction = -1;//方向設置初始位置,比如為0時,也將其設置為1.這樣可以方便后面的處理
??} else {
???this.direction = 1;
??}
?}
}
?
/////////////////////////////////////////////////////////
package baidu;
public class Controller {
?public static void main(String[] args) {
??int time = 0;
??for (int i = 0; i < 32; i++) {
???Ant[] antArray = getAntList(getPoistions(), getDirections(i));
???while (!isAllOut(antArray)) {
????for (Ant ant : antArray) {
?????if (!ant.isOut()) {
??????ant.walk();
?????}
????}
????time++;
????// 查看是否有已經相遇的Ant,如果有則更改其前進方向
????dealEncounter(antArray);
???}
???System.out.println(time);
???// 將時間歸0,這樣可以重新設置條件,再次得到全部走完所需要的時間.
???time = 0;
??}
?}
?/**
? * 這個函數的算法很亂,但暫時能解決問題
? *
? * @param list
? */
?public static void dealEncounter(Ant[] antArray) {
??int num_ant = antArray.length;
??for (int j = 0; j < num_ant; j++) {
???for (int k = j + 1; k < num_ant; k++) {
????if (antArray[j].isEncounter(antArray[k])) {
?????antArray[j].changeDistation();
?????antArray[k].changeDistation();
????}
???}
??}
?}
?/**
? * 因為有5只Ant,所以組合之后有32種組合.剛好用5位二進制來表示,如果為0則表示Ant往0的方向走 如果為1,則表示往27的方向走
? *
? * 注:在通過Ant的構造函數設置初始值時,通過過濾把0修改成了-1.
? */
?public static int[] getDirections(int seed) {
??int result[] = new int[5];
??result[0] = seed % 2;
??result[1] = seed / 2 % 2;
??result[2] = seed / 4 % 2;
??result[3] = seed / 8 % 2;
??result[4] = seed / 16 % 2;
??System.out.println("directions is " + result[0] + "|" + result[1] + "|"
????+ result[2] + "|" + result[3] + "|" + result[4]);
??return result;
?}
?/**
? * 批量設置Ant的初始位置,這樣設置不是十分必要,可以直接在代碼中設置
? *
? * @return
? */
?public static int[] getPoistions() {
??return new int[] { 3, 7, 11, 17, 23 };
?}
?/**
? * 取得設置好初始值的5只Ant
? *
? * @param positions
? * @param directions
? * @return
? */
?public static Ant[] getAntList(int[] positions, int[] directions) {
??Ant ant3 = new Ant(positions[0], directions[0]);
??Ant ant7 = new Ant(positions[1], directions[1]);
??Ant ant11 = new Ant(positions[2], directions[2]);
??Ant ant17 = new Ant(positions[3], directions[3]);
??Ant ant23 = new Ant(positions[4], directions[4]);
??return new Ant[] { ant3, ant7, ant11, ant17, ant23 };
?}
?/**
? * 判斷是否所有的Ant都已經走出了木桿,也就是設置退出條件
? *
? * @param antArray
? * @return
? */
?public static boolean isAllOut(Ant[] antArray) {
??for (Ant ant : antArray) {
???if (ant.isOut() == false) {
????return false;
???}
??}
??return true;
?}
}
?