maven svn
linux命令行打包java代碼,最終生成的XXX3.war為我需要的,它依賴XXX1、XXX2生成的jar
1. 安裝maven
a)安裝jdk
b)配置maven環境
wget http://mirror.bjtu.edu.cn/apache/maven/binaries/apache-maven-3.0.4-bin.zip
unzip -q apache-maven-3.0.4-bin.zip
mv apache-maven-3.0.4 /usr/local/maven
echo 'export M2_HOME=/usr/local/maven
export PATH=$PATH:$M2_HOME/bin' >> /etc/pro
file
source /etc/profile
c)檢查maven
mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: /usr/local/maven
Java version: 1.6.0_22, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_22/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.39.1", arch: "i386", family: "unix"
2. 檢查svn是否支持http方式更新代碼
svn co --username username --password password http://192.168.1.100/svn/trunk/APP_Java/XXX1/
報錯:提示svn: Unrecognized URL schemeSVN更新本地checkout目錄出現這個問題!
原來是svn不識別url,這就需要加載一個模塊 ra_neon!
查看svn版本
svn --version
svn, version 1.6.12 (r955767)
compiled Apr 9 2012, 11:57:15
Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository access (RA) modules are available:
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authenti
cation
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme
發現沒有加載ra_dav 這個模塊
wget http://www.webdav.org/neon/neon-0.29.6.tar.gz
tar xzf neon-0.29.6.tar.gz
mv neon-0.29.6 subversion-1.6.12
重新編譯安裝svn,參考:http://www.linuxeye.com/configuration/317.html
再次查看svn版本
svn --version
svn, version 1.6.12 (r955767)
compiled Apr 9 2012, 11:57:15
Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository access (RA) modules are available:
* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme
3. 從svn庫中更新代碼
mkdir /root/xiangmu
cd /root/xiangmu
svn co --username username --password password http://192.168.1.100/svn/trunk/APP_Java/XXX1/
svn co --username username --password password http://192.168.1.100/svn/trunk/APP_Java/XXX2/
svn co --username username --password password http://192.168.1.100/svn/trunk/APP_Java/XXX3/
你在/root/xiangmu可以看到3個目錄XXX1、XXX2、XXX3
cd /root/xiangmu/XXX1
mvn clean
mvn install package -Dmaven.test.skip=true
cd ../XXX2
mvn clean
mvn install package -Dmaven.test.skip=true
cd ../XXX3
mvn clean
mvn install package -Dmaven.test.skip=true
在/root/xiangmu/XXX3生成target,裡面有XXX3.war,XXX3.war unzip解壓到網站根目錄下就ok
4. maven常用命令
mvn compile
編譯主程序源代碼,不會編譯test目錄的源代碼。第一次運行時,會下載相關的依賴包,可能會比較費時。
mvn test-compile
編譯測試代碼,compile之後會生成target文件夾,主程序編譯在classes下面,測試程序放在test-classes下。
mvn test
運行應用程序中的單元測試
mvn site
生成項目相關信息的網站
mvn clean
清除目標目錄中的生成結果
mvn package
依據項目生成 jar 文件,打包之前會進行編譯,測試。
mvn install
在本地 Repository 中安裝 jar。
mvn eclipse:eclipse
生成 Eclipse 項目文件及包引用定義,注意,需確保定義Classpath Variables: M2_REPO,指向本地maven類庫目錄。