Eclipse SSH 匯入遠端專案(RSE: Remote System Explorer)

搭配【在 Eclipse 上開發 PHP 程式(以 Moodle、EGit、PDT 為例) @ 蛙齋】繼續把整個開發方式記錄下來。這篇文章記錄使用 Eclipse 搭配 Remote System Explorer 這個插件,讓 Eclipse 可以直接透過 SSH 或其他方式直接操作遠端專案。

【安裝 Remote System Explorer 插件】

開啟 Eclipse 後,找到上方選單列的 Help -> Install New Software… -> Work with: Juno – http://download.eclipse.org/releases/juno (這邊要把 juno 換成自己的版本名稱) -> 搜尋 remote -> 勾選下載以下兩個插件

Remote System Explorer End-User Runtime
Remote System Explorer User Actions

001.png

【設定 Remote System Explorer 插件】

安裝完成會要求重新啟動 Eclipse,接著點選右上角的 Open Perspective (有一個 + 的),選擇 Remote System Explorer 之後就可以看到右上角多了一個 Remote System Exploer 的快速切換按鈕了。
002.png
切換到 Remote System Explorer perspective 後,看到左邊 Remote Systems 視窗中有一個 Define a connection to remote system 的按鈕。
003.png
選擇 SSH Only,如果要用其他的協定也可以在這邊使用自己要用的協定。
004.png
輸入遠端主機相關資訊,Parent profile 系統會自動產生,Host name 輸入遠端位址,填寫完畢後按下 Finish。
005.png
在 Remote Systems 可以看到剛剛新增的 remote_moodle 資訊,點進遠端資料夾後會提示登入資訊,登入成功後就可以瀏覽遠端資料夾了。
006.png

【讓 Remote System Explorer 插件支援 PHP】

Remote System Explorer 剛安裝完成的時候,開啟 PHP 檔案時,自動完成的功能會有問題,從參考資料2中發現解法(裡面也包含了很多更詳細的設定),需要做一些設定檔的修改才可以正常使用,首先設定讓所有的檔案都不隱藏(設定檔是隱藏檔),Eclipse -> Window -> Preferences。
007.png
找到 Remote Systems -> Files -> 把 Show hidden files 打勾 -> OK。
008.png
找到 Eclipse 的 workspace 路徑,以 XP 為例,Eclipse 預設在 「C:\Documents and Settings\User\workspace」(User 換成自己登入用的那個),找到 workspace 下 RemoteSystemsTempFiles 資料夾,裡面有個 .project 檔案。
009.png
開啟後加入以下兩行(參考資料2)

<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.php.core.PHPNature</nature>

010.png
存檔後重新啟動 Eclipse,開啟 PHP 檔案試試看,自動完成的功能可以使用囉!
011.png
 
補充:小蛙發現這邊頂多做到自動完成,但其實有一個最最重要的功能並沒有辦法達到,就是 ctrl + click 點選 function 或變數名稱的時候沒辦法直接跳到該 function 或變數所在位置,後來在參考資料2中的問答中找到答案,難怪小蛙昨天試的時候還可以,今天再試就不行了,因為把昨天測試的 project 砍掉了 ><,做法就是 import 一份遠端的檔案到 PHP perspective 中,這樣在 Remote System Explorer 就可以直接有上述功能了!
補充:要讓 RSE 可以直接透過 click + function 就跳到 function 所在的檔案,主要是該檔案必須要開啟過,也就是說如果有用到 get_username(); 這個 function,而這個 function 存在在 fun_lib.php 的話,那麼在開啟過 fun_lib.php 後,custom function 的自動完成以及 click to function 的功能就會自動跑出來囉!試了好久才發現這件事情,為什麼”開啟過”就會自動 link 呢?原因在於開啟之後,會在 RemoteSystemsTempFiles 下面放置下載下來的檔案(開啟的時候 Eclipse 就做下載動作了),最後一個有趣的事情來了,小蛙在編輯 moodle 頁面的時候,裡面有一大堆一大堆看都沒看過的 function,自然也就不知道要去開啟哪些檔案來讓 Eclipse link,後來找到一個方法,在 Remote System Explorer  perspective 下,在要編輯的資料夾上點選滑鼠右鍵 -> Synchronize Cache,這樣就可以把該資料夾下的所有檔案先抓一份回來,剩下的就不說囉(這邊如果檔案數量很大的話,可以透過 Monitor (或 Show in Table 都可以),在要抓回來的資料夾上點選滑鼠右鍵 -> Synchronize Cache 也可以喔!

【Remote System Explorer 將遠端專案匯入成本機專案(補充)】

Remote System Explorer 也可以直接匯入遠端 Project 到本機中,但是這樣在本機修改之後就要自己想辦法”放”回遠端,之前已經做過一些設定,也一併記錄在這邊。
先切換到 PHP perspective。

007.png

新增一個 Project。
008.png
選擇 General -> Project (一般專案)
009.png
輸入專案名稱後點選 Finish。
010.png
切換到 Remote System Explorer perspective 在要匯入的專案上點選滑鼠右鍵,選擇 Import To Project
011.png
這邊卡了非常非常久,因為小蛙要匯入的專案很大,到這個頁面的時候,一直出現 Enter or select a source folder. 的錯誤,導致 Finish 無法成功按下,後來才發現右下角有一個 Querying All 的進度條在跑,大一點的專案甚至可能要等超過十分鐘,Into folder: 這邊選擇要匯入的專案中(這邊例子是剛剛建立的 test)。
012.png
完成後切回 PHP perspective,就可以看到剛剛匯入的專案在這邊了(因為要抓太久,小蛙拿之前抓好的圖來替代),在專案上點選滑鼠右鍵 -> Configure -> Add PHP Support … 讓專案變成 PHP 專案,大功告成!
013.png
參考資料:

  1. 在 Eclipse 上開發 PHP 程式(以 Moodle、EGit、PDT 為例) @ 蛙齋
    http://wazai.net/2539/%E5%9C%A8eclipse%E4%B8%8A%E9%96%8B%E7%99%BCphp%E7%A8%8B%E5%BC%8F%E4%BB%A5moodle%E3%80%81egit%E3%80%81pdt%E7%82%BA%E4%BE%8B
  2. How to setup Eclipse with PHP PDT, Remote System Explorer, Theme Manager, and Drupal Plugins @ Patrick J Waters
    http://www.patrickjwaters.com/blog/2011-07-24/how-setup-eclipse-php-pdt-remote-system-explorer-theme-manager-and-drupal-plugins/35
  3. Code Completion not working with remote file (with RSE) @ stackoverflow
    http://stackoverflow.com/questions/5896909/code-completion-not-working-with-remote-file-with-rse

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *