linux 上 maven 和 nexus3 的详细过程
背景介绍
之前因为做新技术研究,短暂的玩过 nexus3 两天,基于了解也写过一篇 nexus3 搭建的简述,本以为后续要用的时候可以基于简述文档快速上手。结果等到实际工作中,我个人需要完整的设计和搭建一套可用的私服用于公司开发,回过头看文档才发现,之前的了解及文档难以起到有效帮助,故在原文上重新编辑一份。同时也惊醒自己,做技术研究,不说吃透,但一定要有可见可使用的 DEMO。没有达到实际的效果,一切研究都是泡沫。
为何要自己要在 linux 上搭建 maven 和 nexus 好的文章
在 linux 上搭建 maven 个人暂时觉得没有必要,因为 maven 一般在本地开发环境使用。可能一些发布集成平台提供集成 maven 来共享 jar 包。
在 linux 上搭建 nexus 提供隶属于自己的 私服仓库。暂时主要用于管理 个人或组织的私有 jar 包。
前言强调
- jar 包上传到私服 和 从私服下载 jar 包是两套互不干扰的动作。故分开学习和实现 demo 比较好
- jar 包上传和 下载 jar 包都可以在 maven 的 setting.xml 文件中或者工程的 pom.xml 文件中实现。考虑到集中修改共用的优点,我选择在 maven setting.xml 中集中配置。 PS : jar 包上传 pom.xml 必须涉及修改
- setting.xml 文件中 涉及很多 id 的配置。我之前很纠结这些 id 是否一定和 nexus3 上仓库的 id(name) 一一对应。后经过验证。除了 镜像路径的URL 及 账号 密码要对应的上,其他都可以自己有设置。setting.xml 中 name 的设置就更不用说了,随意。
工具介绍
- idea
- nexus3
- maven
配置过程详解
maven 父工程不可缺少
- maven 工程 pom.xml 标签详解
- maven 工程 依赖、继承关系详解
之所以要定义父工程。
其一是因为一般 maven 工程架构设计,都会有
<packaging>pom</packaging>
的父工程。用于统一维护各 jar 包的版本。
其二是可以把上传 jar 的一些统一操作 build 或其他 plug 的配置写在父工程,其子工程可以统一继承。如下:<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"> <modelVersion>4.0.0</modelVersion> <groupId>com.taotao</groupId> <artifactId>taotao-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spring.version>4.1.3.RELEASE</spring.version> <mybatis.version>3.2.8</mybatis.version> <mybatis.spring.version>1.2.2</mybatis.spring.version> <mybatis.paginator.version>1.2.15</mybatis.paginator.version> <mysql.version>5.1.32</mysql.version> <slf4j.version>1.6.4</slf4j.version> <jackson.version>2.4.2</jackson.version> <druid.version>1.0.9</druid.version> <httpclient.version>4.3.5</httpclient.version> <jstl.version>1.2</jstl.version> <servlet-api.version>2.5</servlet-api.version> <jsp-api.version>2.0</jsp-api.version> <joda-time.version>2.5</joda-time.version> <commons-lang3.version>3.3.2</commons-lang3.version> <commons-io.version>1.3.2</commons-io.version> <commons-net.version>3.3</commons-net.version> <pagehelper.version>3.4.2</pagehelper.version> <!-- <pagehelper.version>5.1.11</pagehelper.version>--> <jsqlparser.version>0.9.1</jsqlparser.version> <commons-fileupload.version>1.3.1</commons-fileupload.version> <jedis.version>2.7.2</jedis.version> <solrj.version>4.10.3</solrj.version> </properties> <dependencyManagement> <dependencies> <!-- 时间操作组件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>${joda-time.version}</version> </dependency> <!-- Apache工具组件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>${commons-net.version}</version> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!-- httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency