在macOS的Eclipse匯入Tomcat原始碼為專案的步驟如下。
安裝Apache Ant
建置Tomcat原始碼需要Apache Ant,所以macOS要安裝Ant。
在終端機輸入ant -version
確認系統是否已經有Ant。
$ ant -version
如果沒有安裝Ant則這邊使用Homebrew安裝,輸入brew install ant
開始安裝。
$ brew install ant
安裝完輸入brew info ant
查看Ant的安裝位置為/usr/local/Cellar/ant/1.10.8_2
,此路徑待會設定Eclipse的[Classpath Variables]的ANT_HOME
變數時會用到。
$ brew info ant
ant: stable 1.10.8, HEAD
Java build tool
https://ant.apache.org/
/usr/local/Cellar/ant/1.10.8_2 (1,667 files, 41.8MB) *
Built from source on 2020-09-13 at 10:40:08
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ant.rb
License: Apache-2.0
==> Dependencies
Required: openjdk ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 10,903 (30 days), 27,996 (90 days), 136,973 (365 days)
install-on-request: 8,621 (30 days), 22,010 (90 days), 101,313 (365 days)
build-error: 0 (30 days)
範例安裝的Ant版本為1.10.8_2
。
再次輸入ant -version
確認Ant已安裝。
$ ant -version
Apache Ant(TM) version 1.10.8 compiled on May 10 2020
下載Tomcat原始碼
到Tomcat的github https://github.com/apache/tomcat/
把Tomcat原始碼clone下來到Eclipse的workspace目錄。
/.../workspace/$ git clone https://github.com/apache/tomcat/
原始碼抓下來後用git branch
切換Tomcat版本,例如8.5.x
。
$ git branch 8.5.x
Eclipse設定
在Tomcat目錄下執行ant ide-eclispe
下載Tomcat專案依賴的函式庫,預設下載到/Users/user/tomcat-build-libs/
並建立Eclipse的專案設定檔。
/../workspace/tomcat$ ant ide-eclipse
Buildfile: /Users/user/Documents/workspace/tomcat/build.xml
...
...
ide-eclipse:
[copy] Copying 1 file to /Users/user/Documents/workspace/tomcat
[copy] Copying 1 file to /Users/user/Documents/workspace/tomcat
[mkdir] Created dir: /Users/user/Documents/workspace/tomcat/.settings
[copy] Copying 1 file to /Users/user/Documents/workspace/tomcat/.settings
[echo] Eclipse project files created.
[echo] Read the Building page on the Apache Tomcat documentation site for details on how to configure your Eclipse workspace.
BUILD SUCCESSFUL
Total time: 10 seconds
開啟Eclipse,在Preferences -> Java -> Build Path -> Classpath Variables
新增兩個變數TOMCAT_LIBS_BASE
及ANT_HOME
。
TOMCAT_LIBS_BASE
為Tomcat專案依賴的外部函示庫,預設為/Users/user/tomcat-build-libs
。
ANT_HOME
路徑為Homebrew安裝Ant的目錄,預設在/usr/local/Cellar/ant/1.10.8_2/libexec
。
設定好後在Eclipse功能選單點選File -> Import... -> General -> Existing Projects into Workspace
。
在[Select root directory]選擇Tomcat的目錄位置即可匯入為專案。
匯入後Eclipse [Markers]頁籤會出現Java Problems的錯誤,這不影響執行可以忽略。
在Eclipse的tomcat專案上按滑鼠右鍵 -> Run As -> Java Applications
會出現很多有main
方法的程式,選擇Bootstrap
執行即可啟動專案的Tomcat。
沒有留言:
張貼留言