Maven 3.0.4
項目管理軟件 集jar依賴、項目管理於一體
nexus是一款基於java平臺的maven鏡像服務器軟件,可以用來提供依賴包的發佈、維護和管理,作爲公司或組織內部與公用maven倉庫之間的緩衝鏡像,可以顯著的提高我們的工作效率。
一、安裝JDK
# tar -zxvf jdk-7u3-linux-i586.tar.gz
設置JAVA環境變量
JAVA_HOME=/usr/jdk1.7.0_03
CLASSPATH=$JAVA_HOME/tools.jar:$JAVA_HOME/dt.jar
PATH=$PATH:$JAVA_HOME/bin
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH
# java –version
二、安裝maven
$ su -
#cd /usr/local
#tar -zxvf apache-maven-3.0.4-bin.tar.gz
設置maven環境變量
#cd /root
# vi .bash_profile
M2_HOME=/usr/local/maven
PATH=$PATH:$HOME/bin:$M2_HOME/bin
export M2_HOME PATH
# source.bash_profile
三、安裝nexus
下載地址http://www.sonatype.org/nexus
# tar zxvf nexus-2.0.3-bundle.tar.gz
# ln -snexus-2.0.2 nexus
# cd /usr/local/nexus
# chmod -R a+x bin
# vi /etc/profile
# source /etc/profile
# cd bin
[root@localhost bin]# ./nexus start
訪問 http://172.16.0.128:8081/nexus
點擊右上角Log in
默認用戶名和密碼是:admin/admin123
nexus中的概念:
1、repository:倉庫,就是存放jar依賴包的地方,我們可以在這裏添加新的倉庫,倉庫類型有:proxy(代理類型,可以作爲遠程倉庫的鏡像)、host(本地倉庫,比如公司內部的依賴倉庫等)。
2、倉庫組:repository還有組的概念,可以將多個倉庫作爲一個組,然後對外提供組的訪問地址,這樣對倉庫組進行添加、刪除倉庫就可以動態的改變倉庫的內容。比如有一個jar包是公用倉庫上沒有的,但在jboss的maven倉庫中找到了,那麼我們可以添加一個proxy類型的倉庫,然後加入到這個倉庫組中來,那麼客戶端只要是使用這個組的地址就可以找到這個jar依賴而無需更改倉庫地址了
3、其他權限等管理。
參考:http://jawsy.blog.51cto.com/752812/544682
把包安裝到公司的repository中,需要使用命令
配置本地 e:\mvn\conf\settings.xml
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
cmd: mvn deploy:deploy-file -DgroupId=org.junit-DartifactId=junit -Dversion=3.8.1 -Dpackaging=jar -Dfile=f:\junit-4.0.jar-Durl=http://172.16.0.128:8081/nexus/content/repositories/releases/-DrepositoryId=nexus-releases (-DrepositoryId與settings.xml中的server id相同)
配置Maven從Nexus下載構件
在POM中配置Nexus倉庫
參考:http://jawsy.blog.51cto.com/752812/544721
<repositories>
<repository>
<id>maven-net-cn-yourmall</id>
<name>Maven yourmall Mirror</name>
<url>http://172.16.0.128:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
如果使用mvn deploy還需要在POM中配置,其中<id>要與settings.xml中<server>下<id>相同
<distributionManagement>
<repository>
<id> nexus-releases </id>
<name>InternalReleases</name>
<url>http://172.16.0.128:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-releases</id>
<name>Snapshots</name>
<url>http://172.16.0.128:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
手動部署第三方構件至Nexus
參考:http://jawsy.blog.51cto.com/752812/544721
訪問 http://172.16.0.128:8081/nexus
點擊右上角Log in
默認用戶名和密碼是:admin/admin123
nexus中的概念:
1、repository:倉庫,就是存放jar依賴包的地方,我們可以在這裏添加新的倉庫,倉庫類型有:proxy(代理類型,可以作爲遠程倉庫的鏡像)、host(本地倉庫,比如公司內部的依賴倉庫等)。
2、倉庫組:repository還有組的概念,可以將多個倉庫作爲一個組,然後對外提供組的訪問地址,這樣對倉庫組進行添加、刪除倉庫就可以動態的改變倉庫的內容。比如有一個jar包是公用倉庫上沒有的,但在jboss的maven倉庫中找到了,那麼我們可以添加一個proxy類型的倉庫,然後加入到這個倉庫組中來,那麼客戶端只要是使用這個組的地址就可以找到這個jar依賴而無需更改倉庫地址了
3、其他權限等管理。
參考:http://jawsy.blog.51cto.com/752812/544682
把包安裝到公司的repository中,需要使用命令
配置本地 e:\mvn\conf\settings.xml
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
cmd: mvn deploy:deploy-file -DgroupId=org.junit-DartifactId=junit -Dversion=3.8.1 -Dpackaging=jar -Dfile=f:\junit-4.0.jar-Durl=http://172.16.0.128:8081/nexus/content/repositories/releases/-DrepositoryId=nexus-releases (-DrepositoryId與settings.xml中的server id相同)
配置Maven從Nexus下載構件
在POM中配置Nexus倉庫
參考:http://jawsy.blog.51cto.com/752812/544721
<repositories>
<repository>
<id>maven-net-cn-yourmall</id>
<name>Maven yourmall Mirror</name>
<url>http://172.16.0.128:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
如果使用mvn deploy還需要在POM中配置,其中<id>要與settings.xml中<server>下<id>相同
<distributionManagement>
<repository>
<id> nexus-releases </id>
<name>InternalReleases</name>
<url>http://172.16.0.128:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-releases</id>
<name>Snapshots</name>
<url>http://172.16.0.128:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
手動部署第三方構件至Nexus
參考:http://jawsy.blog.51cto.com/752812/544721
maven-3.3.9版本需要將archetype:create改爲archetype:generate -DarchetypeCatalog=internal -DinteractiveMode=false
建一個 JAVA 項目 : mvn archetype:create -DgroupId=com.yunmall -DartifactId=App
建一個 web 項目 : mvn archetype:create -DgroupId=com.yunmall -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp生成eclipse項目
mvn -Dwtpversion=1.0 eclipse:eclipse
打包
mvn package -Dmaven.test.skip=true將jar包copy到工程目錄下的lib裏面
mvn dependency:copy-dependencies -DoutputDirectory=lib -DincludeScope=compile
1、排除依賴包
<dependency>
<groupId>com.xxx.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
2、過濾文件
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<!-- 包含 -->
<includes>
<include>**/*.vm</include>
<include>**/*.properties</include>
</includes>
<!-- 排除 -->
<excludes>
<exclude>**/*.log</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.log</exclude>
</excludes>
</resource>
</resources>
</build>
jetty插件
<pluginRepositories>
<pluginRepository>
<id>spring-maven-release</id>
<name>Spring Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.4.v20120524</version>
<configuration>
<webAppConfig>
<contextPath>/${project.artifactId}</contextPath>
</webAppConfig>
</configuration>
</plugin>
</plugins>
<finalName>web.yunpay</finalName>
</build>
3、eclipse-indigo導入使用maven命令創建的web項目,還需要手動轉換成web項目的問題
eclipse-indigo解決方案:安裝插件 http://download.eclipse.org/m2e-wtp/releases/juno