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