Maven 专题

目录:

Maven的安装

Eclipse安装Maven插件

Nexus私服搭建

Maven+Nexus配置

发布自己的构件(至Nexus)

创建maven多模块工程group

整理中[...]


先放一个概要图:

 

 

Maven的安装

 

 

Eclipse安装Maven插件

 

 

Nexus私服搭建

1)下载、安装(最新的Nexus需要jdk1.7及以上)

2)配置Nexus

a)安全性设置

b)仓库配置(Repository)

如下图:

从上图可知,仓库分成proxy、hosted、group等几类。

proxy可以理解为代理库,例如Central中央仓库,Nexus从中央仓库拉下jar包,作为二级缓存方便团队实用。

如上图,设置Download Remote Indexes会从中央仓库下载索引文件(lucene索引),团队开发时从该索引中检索jar包,下载后保存在

http://localhost:8081/nexus/content/repositories/central/

其他连个proxy仓库也可以打开Download Remote Indexes。

 

对于group类型的Public Repositories可以理解为是多个仓库的合集,如图:

 

Maven+Nexus配置

修改~/.m2/setting.xml

如下:(摘抄自http://blog.linguofeng.com/archive/2012/08/10/maven-nexus-install.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?xml version= "1.0" encoding= "UTF-8" ?>
           xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
 
   <!-- 配置central镜像地址为本地仓库,加速索引速度 -->
   <mirrors>
     <mirror>
       <id>central</id>
       <mirrorOf>central</mirrorOf>
       <name>central</name>
       <url>http: //127.0.0.1:8081/nexus/content/repositories/central</url>
     </mirror>
   </mirrors>
   
   <!-- 配置发布仓库,第一个为正式版仓库,第二个为快照版仓库。 -->
   <profiles>
     <!-- 执行:$ mvn release:prepare 命令时会打包并发布到该仓库。 -->
     <profile>
       <id>nexus</id>
       <repositories>
         <repository>
           <id>nexus</id>
           <name>local private nexus</name>
           <url>http: //127.0.0.1:8081/nexus/content/groups/public</url>
         </repository>
       </repositories>
     </profile>
     <!-- 执行:$ mvn deploy 命令时会打包并发布到该仓库。 -->
     <profile>
       <id>nexus-snapshots</id>
       <repositories>
         <repository>
           <id>nexus-snapshots</id>
           <name>local private nexus snapshots</name>
           <url>http: //127.0.0.1:8081/nexus/content/groups/public-snapshots</url>
         </repository>
       </repositories>
     </profile>
   </profiles>
 
   <!-- servers节点的属性是在向仓库发布时使用 -->
   <servers>
     <server>
       <id>nexus-releases</id>
       <username>admin</username>
       <password>admin123</password>
     </server>
     <server>
       <id>nexus-snapshots</id>
       <username>admin</username>
       <password>admin123</password>
     </server>
   </servers>
 
   <!-- 激活配置 -->
   <activeProfiles>
     <activeProfile>nexus</activeProfile>
     <activeProfile>nexus-snapshots</activeProfile>
   </activeProfiles>
</settings>

Eclipse中队Maven User Settings进行配置,如图:

Update Settings,然后就快在Maven项目中引入依赖。

如果是第一次加载,Nexus将从中央仓库下载,下载完毕后可以在

http://localhost:8081/nexus/content/groups/public/org/springframework/spring-core/

下找到相应的spring-core文件。

发布自己的构件(至Nexus)

配置settings.xml

1
2
3
4
5
6
7
8
9
10
11
12
<servers>
   <server>
     <id>releases</id>
     <username>admin</username>
     <password>***</password>
   </server>
   <server>
     <id>snapshots</id>
     <username>admin</username>
     <password>***</password>
   </server>
</servers>

在项目pom.xml文件中添加:

1
2
3
4
5
6
7
8
9
10
11
12
<distributionManagement>
     <repository>
         <id>releases</id>
         <name>Nexus Release Repository</name>
         <url>http: //localhost:8081/nexus/content/repositories/releases/</url>
     </repository>
     <snapshotRepository>
         <id>snapshots</id>
         <name>Nexus Snapshot Repository</name>
         <url>http: //localhost:8081/nexus/content/repositories/snapshots/</url>
     </snapshotRepository>
</distributionManagement>

必须保证:settings.xml和pom.xml中id是一一对应的。

然后mvn deploy即可。

在Nexus中可以search到自己的构件:

在配置的仓库中也可以找到具体文件的位置:

http://localhost:8081/nexus/content/repositories/snapshots/cn/fox/test/

 

 

创建maven多模块工程group

1)先创建父工程

创建一个maven工程(Maven project,选择quickStart),除了pom.xml文件其他都删掉,然后修改pom.xml。

将<packaging>jar</packaging>修改成<packaging>pom</packaging>。

如果提示有错,用maven-》update project。

2)创建子模块

创建一个maven模块(Maven module)。

父工程的pom文件自动添加了以下内容:

<modules>
  <module>children1-demo</module>
</modules>

3)优化、调整配置

父子项目有继承关系,如果子项目的一些属性都一样,可以上移到父项目中设置,子项目无需重复设置。

还有几个注意点:

统一指定版本号 <properties>

统一依赖管理 <dependencyManagement>

统一插件管理 <pluginManagement>

 

 

相关参考资料

http://juvenshun.iteye.com/blog/349534 [Nexus入门指南]

 

 

 

----------------------------------------------------

1.从svn中迁出maven项目

a)从svn资源库“迁出”(指定的workspace)

b)import-》Existing Maven Projects

上传java项目时忽略eclipse项目配置文件(.settings/.classpath/.project/target等) (svn ignore)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值