1.1 什么是maven
是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的
1.2Maven的好处
依赖管理:jar包的统一管理
一键构建
分模块开发,提高开发效率
1.3配置本地仓库
在maven的conf/settings.xml中加入
<localRepository>E:\repository</localRepository>
把本地仓库的地址加入进去
Maven生命周期
Clean生命周期
Clean
Default生命周期
Compile test package install deploy(发布到私服上)
Site生命周期
Site
导包前重建索引
添加 Maven Repositories
bulid Index
添加包需要注意
jsp javax.servlet 2.0
servlet javax.servlet 2.5
的scope依赖范围
- compile 默认的
- provided 不打包
- runtime
- Test
5.3.1 Compile struts2-core
编译(compile)时需要 测试时需要,,运行时需要,打包时需要
5.3.2 Provided jsp-api.jar servlet-api.jar
编译(compile)时需要,测试(test)时也需要 ,运行时不需要,打包时不需要
5.3.3 Runtime 数据库驱动包
编译时不需要,测试时需要,,运行时需要,打包时需要
5.3.4 Test junit.jar
编译时不需要,测试时需要,运行时不需要,打包也不需要
私服nexus
安装nexus
nexus.bat install
启动服务
nexus.bat start
启动失败是因为jdk位置不对
在nexus/bin/jsw/conf/wrapper.conf中 15行
填写jdk的bin/java.exe位置
Virtual 虚拟仓库
Proxy 代理仓库
Hosted 宿主仓库 本地仓库
Group 组
上传到私服
1.修改上传的账号密码
在maven/conf/settings.xml
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
2.配置pom.xml
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
从私服下载
1。修改settings.xml
<profile>
<!--profile的id-->
<id>dev</id>
<repositories>
<repository>
<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
<id>nexus</id>
<!--仓库地址,即nexus仓库组的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下载releases构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载snapshots构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
//激活
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
ok了