天天看點

新浪舊事-svn服務端配置及在MyEclipse中的使用

        首先,在http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=11129&expandFolder=11129&folderID=91(現在是http://subversion.apache.org/packages.html)上下載下傳Setup-Subversion-1.6.6.msi, 在http://tortoisesvn.net/downloads上下載下傳TortoiseSVN-1.6.9.19725-win32-svn-1.6.12.msi。

        接着我們安裝運作Setup-Subversion-1.6.6.msi 安裝界面比較簡單,我們主要關注安裝位置,假定我們安裝在預設位置C:\Program Files\Subversion。

        現在我們建立repository,使用的指令是svnadmin。本例中,我們要在c:\svnroot下建立repository。那麼我們使用的指令行如下:

C:\Program Files\Subversion\bin>svnadmin create c:\svnroot
C:\Program Files\Subversion\bin>
           

        建立好repository之後,我們要對Server 進行一些簡單的配置。打開c:\svnroot下的conf目錄,編輯svnserve.conf,修改裡面的内容。

auth-access = write
password-db = passwd
anon-access = read
           

        前面的#去掉,打開這個注釋。

        同時修改anon-access = none

        現在svnserve.conf的片斷看起來類似:

[general]
### These options control access to the repository for unauthenticated

### and authenticated users. Valid values are "write", "read",

### and "none". The sample settings below are the defaults.

anon-access = none

auth-access = write

### The password-db option controls the location of the password

### database file. Unless you specify a path starting with a /,

### the file’s location is relative to the directory containing

### this configuration file.

### If SASL is enabled (see below), this file will NOT be used.

### Uncomment the line below to use the default password file.

password-db = passwd

### The authz-db option controls the location of the authorization

### rules for path-based access control. Unless you specify a path

### starting with a /, the file’s location is relative to the the

### directory containing this file. If you don’t specify an

### authz-db, no path-based access control is done.

### Uncomment the line below to use the default authorization file.

# authz-db = authz

### This option specifies the authentication realm of the repository.

### If two repositories have the same authentication realm, they should

### have the same password database, and vice versa. The default realm

### is repository’s uuid.

# realm = My First Repository
           

    修改好 svnserve.conf 後,我們再修改   passwd 檔案。加入我們需要的使用者名 joe 和密碼 123 。 passwd 内容如下:

### This file is an example password file for svnserve.

     ### Its format is similar to that of svnserve.conf. As shown in the

     ### example below it contains one section labelled [users].

     ### The name and password for each user follow, one account per line.

     [users]

     # harry = harryssecret

     # sally = sallyssecret

     joe = 123
           

    現在就可以啟動server了。啟動的方法有很多種,在這裡針對本文的環境我們介紹兩種,一種是以deamon方式調用,一種是以Windows Service的方式調用。

    如果是以deamon的方式調用,那麼指令行如下:

C:\Program Files\Subversion\bin>svnserve -d -r c:\svnroot
           

    服務端開始運作後,我們就可以關注一下用戶端的問題了。TortoiseSVN的安裝我沒有什麼可說的,就是一路的NEXT。這裡我們描述一下我們的用于test的項目。以本文為例假定我們的項目目錄是D:\mytemp\svn_test1,假定目錄下有一個test1.txt檔案。在svn_test1上按右鍵選TortoiseSVN–>Import 在URL of repository裡輸入svn://192.168.159.129/svnroot 點選OK後,按提示輸入使用者名和密碼,就可以把項目導入Subversion 。好了,現在我們可以試一下,看看剛才我們導入的内容,并開始正常的update,commit工作吧。我們删除svn_test1裡面的所有檔案。然後在svn_test1目錄上按右鍵選SVN Checkout URL of repository裡輸入的仍是svn://192.168.159.129/svnroot Checkout directory裡輸入的是D:\mytemp\svn_test1 Checkout Depth 選擇Fully recursive,點選OK後,按提示輸入使用者名和密碼,這時我們再看svn_test1目錄,就可以看到我們導出的test1.txt檔案了。

    我們打開test1.txt檔案嘗試修改并更新一下。我們在test1.txt裡加上一行“哈爾濱市,高宏偉 QQ:21807822”,然後我們在svn_test1目錄上按右鍵選svn commit,在message中我們可以輸入一些日志來标志本次修改,然後點選OK,按提示輸入使用者名密碼就可以送出了。update的操作也是類似,隻不過是相反的操作。

    界面的操作不太容易用文字來表達,但界面很直覺,相信大家擺弄擺弄就可以搞定。剛才為了保證文章的連續性,我們沒有說明如何以Windows Service 的方式來調用server。生成svn服務的指令如下:

C:\>sc create svn binpath= "C:\Program Files\Subversion\bin\svnserve.exe –service -r c:\svnroot" displayname= "Subversion Server" depend= tcpip start= auto
     C:\>net start svn
           

    這裡要特别注意一下sc指令的使用。主要是注意一下=号後面的空格和svn路徑的空格。

    1. 如果你沒有建立服務成功,那你就不要安裝到Program Files目錄下,因為它帶了一個空格,你可以安裝到一個比較簡單的目錄下再試試,如c:\svn_server。

    2. 如果安裝到這樣簡單的目錄還不能建立成。那你要注意binpath的等号後面有一個空格。你一定要完全按照上面的格式來寫。

    3. 實在不行你就把所有的環境先都配成和本文一樣,然後再直接粘貼過去,這樣可以保證你運作成功。等所有的問題都沒有了。你再按照你的想像重新安裝一次,看看你的問題出在哪兒,這樣也好有個對比。

    版本庫管理:

    建立版本庫:

    在伺服器端,需要建立版本庫的檔案夾内點右鍵,在右鍵菜單中 TortoiseSVN-->Create repository here。

    導入源代碼:

    找到源代碼目錄,點右鍵,在右鍵菜單中  TortoiseSVN-->Import...  彈出對話框URL of  Repository中填寫為 file:///D:\Dev_Tools\Subversion\svnrepos\FGIS,也就是建立庫的檔案目錄,最後點選 【OK】按鈕,導入資料。

    注意:   導入資料目錄下源代碼無關檔案(源代碼編譯時的中間檔案)都删除,然後導入。例如:*.ncb、*.lib等

    在MyEclpse中使用:

    打開SVN 資源庫視窗,右鍵點選,建立資源庫,在URL對話框中輸入:file:///D:\Dev_Tools\Subversion\svnrepos\FGIS