Maven: POM, Setting, Repository
来源:互联网 发布:华美淘宝客 编辑:程序博客网 时间:2024/06/05 05:27
概念
POM
POM代表面向项目的模型“project Object Model”。每一个Maven项目中都维护这一个pom.xml,Maven项目包括配置文件,依赖关系,代码位置,等等。在Maven里面中维护好这个pom.xml文件就可以管理好项目的所有元素了。
- 具体POM XML中元素的解释参考:http://maven.apache.org/pom.html
- POM XML对应的xml schema: http://maven.apache.org/xsd/maven-4.0.0.xsd
Setting
在settings.xml文件中的settings元素包含了Maven执行时的参数,就像pom.xml。settings包括了local repository, remote repository,mirror和验证等信息。
settings.xml存在如下两个地方:
- Maven的安装目录:$M2_HOME/conf/settings.xml(全局配置)
- 用户目录: ${user.home}/.m2/settings.xml(用户级别的配置))
具体的Setting字段的配置:https://maven.apache.org/settings.html
Repository
Repository Manager是一个专门的服务器,用来管理两进制组件。
在Mavan中,Repository Manager可以用来如下目的:
- 用来作为公共的Maven Repositories.
- 用来depoly我们的Maven项目到Repository中,进行统一管理。
具体说明: https://maven.apache.org/repository-management.html
实例
选择Nexus SSO作为Repository Manager,然后depoly自己的一个plugin项目到此Repository Manager中。
步骤
1.下载Nexus SSO: http://www.sonatype.org/nexus/go/. 选择Windows版本ZIP版本,解压后运行。
D:\webServers\nexus-2.11.3-01-bundle\nexus-2.11.3-01\bin>nexus.bat startwrapper | The nexus-webapp service is not installed - The specified service does not exist as an installed service. (0x424)Press any key to continue . . .D:\webServers\nexus-2.11.3-01-bundle\nexus-2.11.3-01\bin>nexus.bat installwrapper | nexus installed.D:\webServers\nexus-2.11.3-01-bundle\nexus-2.11.3-01\bin>nexus.bat startwrapper | Starting the nexus service...wrapper | Waiting to start...wrapper | Waiting to start...wrapper | Waiting to start...wrapper | Waiting to start...wrapper | nexus started.
nexus需要install后,再start. 启动成功后,变可以访问Nexus服务器了。
2.访问Nexus http://localhost:8081/nexus 。使用admin/admin123登录后,进行管理和查看。
Nexus里面自带的Repository可以基本满足需求。我会用到如下的两个Repository:
- Snapshots: http://localhost:8081/nexus/content/repositories/releases/
- Releases: http://localhost:8081/nexus/content/repositories/snapshots/
Snapshots用于存放临时不稳定版本,Releases用于存放发布的稳定版本。
3.配置 pom.xml文件,用于depoly时artifact的分发。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <groupId>com.lewi</groupId> <artifactId>plugin</artifactId> <version>1.2-SNAPSHOT</version> <packaging>maven-plugin</packaging> ... <distributionManagement> <repository> <id>nexus</id> <name>Nexus Release Repository</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>...</project>
4.配置settings.xml中的server,用于pom.xml中server的认证。
<servers> <server> <id>nexus</id> <username>deployment</username> <password>deployment123</password> </server></servers>
5.运行配置好的pom.xml对应项目,mvn deploy. 可以查看到build成功。然后再到Repository Manager中的Snapshots下,可以看到到编辑后的artifact存在了。如下图。
总结
本文首先说明了Maven中主要元素和配置的概念,然后用一个具体的Repository Manager实例,演示了Maven如何和具体的Repository结合。
Reference:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
- Maven: POM, Setting, Repository
- Setting Up a Maven Repository
- Maven 之setting.xml pom.xml
- Maven 之setting.xml pom.xml
- nexus maven setting 和pom 文件配置
- maven配置文件setting.xml、pom.xml
- maven的setting配置文件中mirror和repository的区别
- 【Maven】setting.xml中mirror和repository的关系
- maven的setting配置文件中mirror和repository的区别
- Maven使用心得 -- 常用setting.xml和pom.xml配置
- maven配置setting.xml文件、POM.xml详解
- maven配置setting.xml文件、POM.xml详解
- maven的setting.xml文件和pom.xml文件
- maven系列四 —— maven配置文件详解(setting.xml 和 pom.xml)
- maven setting
- maven setting
- maven setting
- maven setting
- shell变量详解
- H264编码原理以及I帧B帧P帧
- Single Number II
- java-I/O操作工具类
- metaq架构原理
- Maven: POM, Setting, Repository
- Android5.1 SystemUI 启动流程
- Android中PopupWindow点击窗口之后消失后处理其他业务
- IOS应用程序发布到苹果APP STORE
- Cocos2d-x 3.2 之 别踩白块(第三篇)
- @Autowired与@Resource的区别
- swift实作app 交流分項三(畫面切換)
- 关于bochs用X11启动的说明
- 设计模式之二十四:访问者模式(Visitor)