Maven私服Nexus3.x环境构建操作记录
参考链接:https://www.cnblogs.com/kevingrace/p/6201984.html
个人测试,我的pom.xml文件,里面添加了说明注释
<?xml version="1.0" encoding="UTF-8"?> <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.zx</groupId> <artifactId>robot</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <!--<version>1.0.0-RELEASES</version> --> <name>robot Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <org.springframework.version>4.3.16.RELEASE</org.springframework.version> </properties> <dependencies> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.9</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.4.RELEASE</version> <scope>test</scope> </dependency> <!-- druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.27</version> </dependency> <!-- spring framework start --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-messaging</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> <version>4.0.0.RELEASE</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.6.7</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.6.7</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.8.8</version> </dependency> <!-- spring framework end --> <!-- MyBatis start --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.1</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <!-- MyBatis end --> <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-websocket-api --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-websocket-api</artifactId> <version>7.0.65</version> <!-- 要加scope,否则,此依赖可能和tomcat自带的tomcat-websokcet.jar冲突,导致websocket链接建立不成功 --> <scope>provided</scope> </dependency> <!-- MySQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.37</version> </dependency> <!-- slf4j start --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.10</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.2</version> </dependency> <!-- slf4j end --> <!-- Jstl start --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- Jstl end --> <!-- Servlet start --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- Servlet end --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>5.0.0.Alpha2</version> </dependency> <!-- aop start --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>3.0.6.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.9.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.0</version> </dependency> <!-- aop end --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.6.7</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.5</version> </dependency> <!-- config redis data and client jar --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.8.1.RELEASE</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> </dependencies> <repositories> <repository> <id>maven-public</id> <name>maven-public</name> <url>http://192.168.0.210:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <!-- Snapshot包的管理 1)修改Maven的settings.xml文件,加入认证机制 <servers> <server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server> </servers> 2)修改工程的Pom文件,添加下方distributionManagement内容 注意:snapshotRepository中的id的名字nexus要跟maven/conf/settings.xml文件中的名字一定要对应上 3)上传到Nexus上 1-项目编译成的jar是Snapshot(POM文件的头部) <groupId>com.woasis</groupId> <artifactId>test-nexus</artifactId> <version>1.0.0-<span style="color: #ff0000;">SHAPSHOT</span></version> <packaging>jar</packaging> 2-使用mvn deploy命令运行即可(运行结果在此略过) 3-因为Snapshot是快照版本,默认他每次会把Jar加一个时间戳,做为历史备份版本。 --> <distributionManagement> <snapshotRepository> <id>nexus</id> <name>Nexus Snapshot</name> <url>http://192.168.0.210:8081/repository/maven-snapshots/</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> <site> <id>nexus</id> <name>Nexus Sites</name> <url>dav:http://192.168.0.210:8081/repository/maven-snapshots/</url> </site> <!-- Releases包的管理 1)与Snapshot大同小异,只是上传到私服上的Jar包不会自动带时间戳 2)与Snapshot配置不同的地方,就是工程的PMO文件,额外加入repository配置 3)打包的时候需要把Snapshot去掉,可以换成RELEASES --> <repository> <id>nexus</id> <name>Nexus Snapshot</name> <url>http://192.168.0.210:8081/repository/maven-releases/</url> <uniqueVersion>false</uniqueVersion> </repository> </distributionManagement> <build> <finalName>robot-1.0.0-SNAPSHOT</finalName> <resources> <!-- 这里的resource配置的是需要导入到项目的资源文件夹 --> <resource> <directory>src/main/resources</directory> </resource> <!-- 这里的${profiles.dir}是你上面配置的属性值,用于动态替换,比如打包的时候输入的是-Pdev则这里就是的${profiles.dir}就是dev的值 --> <resource> <directory>src/main/profile/${profiles.dir}</directory> </resource> </resources> <plugins> <!-- 编译install --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打jar包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <manifest> <mainClass>com.alibaba.dubbo.container.Main</mainClass> <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本,但是无法做到发布到nexus时,也不带时间戳 --> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> <profiles> <profile> <!-- 开发环境 --> <id>dev</id> <properties> <!-- 这里的属性名是随便取的,可以在后续配置中引用 --> <profiles.dir>dev</profiles.dir> </properties> <!-- 是否默认 --> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <!-- 线上环境 --> <id>pro</id> <properties> <!-- 这里的属性名是随便取的,可以在后续配置中引用 --> <profiles.dir>pro</profiles.dir> </properties> </profile> <profile> <!-- 本地环境 --> <id>local</id> <properties> <!-- 这里的属性名是随便取的,可以在后续配置中引用 --> <profiles.dir>local</profiles.dir> </properties> </profile> </profiles> </project>