星期日, 2月 06, 2005

Apache, Tomcat & Axis (on windows)

為了幫朋友研究些關於 Java web service 的東西要把 server 架起來. 又因為 client 端只有 windows 版的, 在只有一台機器的情況下, 只好在 windows 上把 server 架起來. 事實上步驟不難, 找對東西下載然後點幾下就好了.

要裝的東西包括:
1. Apache for windows, 我用的是 2.0.52 (最新的 stable).
    http://httpd.apache.org/download.cgi
2. Apache Jakarta Tomcat 5.5.7.
    http://jakarta.apache.org/site/binindex.cgi 搜尋 tomcat
3. Apache Webservises project Axis 1.2RC2
    (這是用 java 的, 如果要用 C++ 則是 Axis C++).
    http://ws.apache.org/axis/
4. Sun JDK 5.0 (1.5) update 1.
    http://java.sun.com/j2se/1.5.0/download.jsp
5. JavaBeans Activation Framework, JAK 1.0.2.
    http://java.sun.com/products/javabeans/glasgow/jaf.html

其中 dependency 是:
1. independent.
2. depend on 1. and 4.
3. depend on 2. and 5. (但安裝時只要 2.)
4. independent.
5. depend on 4.

所以以下是建議安裝順序:
1) 下載 1. 和 4.
2) 因為 jdk 很大, 所以 Apache 一定先抓完, 就順手裝起來.
3) 然後可以來抓 2. 和 3. 等到 jdk 裝起來就把 Tomcat 裝起來, 接著裝 Axis.
4) 最後抓 5. 在 JAF 裝起來之前 Tomcat 就可以動了, 可以稍微玩一下.
    用 browser 連到 localhost:8080
    (Tomcat 預設 port 為 8080, 有自行更改請改到相應的地方).
5) JAF 抓下來是 zip 檔. 把其中的 activation.jar 移到 Axis 所在目錄的 WEB-INF\lib 下就好了.
6) 開 browser 連到 localhost:8080/Axis 應該就會看到 Axis 的起始畫面. 點 Validate (http://localhost:8080/Axis/happyaxis.jsp), 核心元件 (core component) 應該都裝起來了, 要裝兩個選擇性元件的話再去頁面上给的 link 抓.
8) 回到 Axis 起始畫面, 點 Call a local endpoint, 可能會出現一個 xml, 其中有一行
java.lang.RuntimeException: No compiler found in your classpath! (you may need to add 'tools.jar')
那就代表碰上了和我同樣的問題. 解決的方法是在右下角圖示中找出 Apache Tomcat, 按右鍵選 configure, 在跳出的視窗中選 Java 頁面, 在 Java Classpath 的後面加上到 tools.jar 的路境. 以下是我的設定:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\bootstrap.jar;C:\Program Files\Java\jdk1.5.0_01\lib\tools.jar
回到這個設定視窗的 General 頁面, 按 Stop 之後按 Start 重新啟動 Tomcat 就可以正常運作了.

要注意的幾點:
1. jdk 安裝檔和裝起來都很佔空間, 所以要留夠多硬碟.
2. Axis 抓下來也是一個 zip, 只要把 webapps\axis 整個目錄移到 Tomcat 的 webapps 下就可以了. 其他 document 和 sample 可以留在別的地方.
3. 如果 用 Tomcat 4.x 和 jdk 1.4 那 activation.jar 要放在 Tomcat 目錄的 common/lib 下 (happyaxis.jsp 上特別註明).

因 為我還必須同時讓 IIS 執行 (做別的事), 所以 Apache 不能聽 port 80 而改到 8080. 可是這是 Tomcat 的預設 port 造成 Tomcat 執行失敗. 在找不到設定工具的情況下直接去改設定檔. 幸好設定檔都是 xml, 格式不難, 只要把 Tomcat 目錄下 conf\server.xml 其中一個 tag <Connector port="8080" ... > 改成要的 port 就好了.

0 Comments:

張貼留言

<< Home