1、配置自己的maven ,并配置自己的maven仓库
2、建立的项目中 src/main/resource 放配置文件 约定优于配置
src/test/resource 放配置文件
3、pom.xml中配置依赖,可以自动下载包,中央找pom.xml
4 例如 三个项目,user-core user-log user-service
前两个要 clean install 第三个 引用 ,如果第一个user-core导入过commons-logging ,则导入user-core项目的项目也会自动导入commons-logging包.
com.yanlei.use
user-log
0.0.1-SNAPSHOT
${project.groupId} // 表达式,表示本项目
user-core
${project.version} //表达式
6 依赖传递. c-->b b-->a 所以c依赖a
D-->A A-->B1 D-->C C-->B2 D依赖B1(D-A-B1,D-C-B2 那个先写依赖那个) (想依赖B2, 在A中
D-->A A-->B1 D-->C C-->B2 D-B3 D依赖B3 (D-A-B1,D-C-B2,D-B3)直接依赖层次短的
7 聚合三个模块,,, 写个简单的maven项目 pom.xml中 ,也可以吧pom放在三个模块的共同目录下, 然后改下路径 user-core.xml即可.
../user-core
../user-log
../user-service
父类一样是新建个简单的maven项目,可以公共的部分有
父类pom.xml
http://maven.apache.org
UTF-8
//只是负责管理,继承他的项目并不会拥有它的包
junit
junit
3.8.1
commons-logging
commons-logging
1.2
子类
com.yanlei.user
user-parent //父类的
0.0.1-SNAPSHOT
../user-parent/pom.xml //父类的路径,如果是在公共目录下,可以写成pom.xml
user-service
jar
user-service
junit
junit //可以不用写版本了,父类中有版本
com.yanlei.user
user-log
0.0.1-SNAPSHOT //自己依赖的包
com.yanlei.user
user-core
${project.version}
commons-logging
commons-logging //可以不用写版本了,父类中有版本
9 添加 nexus sonatype 类似私服,建在自己的局域网,方便大家下载,不用每次都去中央仓库
下载 nexus-2.10.0-02-bundle.zip包,配置其 bin 到path下, 然后修改 bin/jsw/conf/wrapper.java.command 为java的绝对路径,包含Java程序
cmd下安装nexus install 服务,然后启动 ,
进行访问 http://localhost:8081/nexus/#welcome login admin admin123
10 使用nexus .
host类型的工厂,针对内部, 面向内网. mvn deploy
可以吧自己的项目提交跟工厂,根据snapshot,releases 分,3rd 针对找不到pom.xml的包,自己去官网下,,,,手动,导入
center工厂 nexus中没有的包, 去中央工厂下载,然后放入数据放入center工厂,
(以后新增一个包,如果组中的各工厂有,从nexus中下载,如果没有,通过nexus 到中央工厂下载)
方法一: 可以在父类中,一个一个的将仓库导入,但是太麻烦,可以把几个仓库组合成一个组,放入public Respositories 然后用他一个URL就方便了许多.
nexus
Nexus Repository
http://localhost:8081/nexus/content/groups/public/ //其他人使用,可以改变ip地址即可
true
true
生成仓库
nexusRepo
nexus
Nexus Repository
http://localhost:8081/nexus/content/groups/public/
true
true
激活上面仓库: 注销 父类中的
nexusRepo
12
maven-model-builder-3.3.9中的pom.xml,若想改变中央工厂的属性,在setting中,
这样就可以使新的中央工厂的配置生效
13 注:装了nexus后,本地仓库有,而nexus没有, 也会先找nexus,可以更新下索引
14
发布自己的项目, parent中pom.xml -----------------clean deploy
不过在parent.xml中
user-release //发布release程序
user release resp
http://localhost:8081/nexus/content/repositories/releases/ 到release的工厂
user-snapshots //发布snapshots的程序
user snapshots resp
http://localhost:8081/nexus/content/repositories/snapshots/ 到snapshot的工厂
然后再setting.xml中授权,这样就可以把 自己的项目发布到 nexus的仓库中,.....也再一次说明了,host的仓库,是针对内部的仓库. 接受内部项目....center仓库 接受外部jar包
user-release //id跟上面的id匹配
admin
admin123
user-snapshots //id跟上面的ID匹配
admin
admin123
仓库必须为两个,一个release,一个snapshot的. ..
部署的话,还是按照以上,先配置