标签:aliyun space 统一 you txt web 包冲突 gre 网站
在maven发展之前,传统的jar包管理我们一般会用ant+lvy来管理jar包,它有显而易见的两个缺点,
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- START SNIPPET: superpom --> <project> <modelVersion>4.0.0</modelVersion> <repositories> <repository> <id>central</id> <name>Central Repository</name> <url>http://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <name>Central Repository</name> <url>http://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> <releases> <updatePolicy>never</updatePolicy> </releases> </pluginRepository> </pluginRepositories> <build> <directory>${project.basedir}/target</directory> <outputDirectory>${project.build.directory}/classes</outputDirectory> <finalName>${project.artifactId}-${project.version}</finalName> <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory> <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>${project.basedir}/src/test/resources</directory> </testResource> </testResources> <pluginManagement> <!-- NOTE: These plugins will be removed from future versions of the super POM --> <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </pluginManagement> </build> <reporting> <outputDirectory>${project.build.directory}/site</outputDirectory> </reporting> <profiles> <!-- NOTE: The release profile will be removed from future versions of the super POM --> <profile> <id>release-profile</id> <activation> <property> <name>performRelease</name> <value>true</value> </property> </activation> <build> <plugins> <plugin> <inherited>true</inherited> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <inherited>true</inherited> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <inherited>true</inherited> <artifactId>maven-deploy-plugin</artifactId> <configuration> <updateReleaseInfo>true</updateReleaseInfo> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project> <!-- END SNIPPET: superpom -->
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>osc</id> <mirrorOf>central</mirrorOf> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> <mirror> <id>osc_thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <url>http://maven.oschina.net/content/repositories/thirdparty/</url> </mirror>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency> <groupId>opensymphony</groupId> <artifactId>webwork</artifactId> <version>2.2.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </exclusion> </exclusions> </dependency>
们在用maven构建java项目时,最常用的打包命令有mvn clean ,mvn package、mvn install、deploy,这四个命令都可完成打jar包或war(当然也可以是其它形式的包)的功能。
但是这并不是maven的生命周期,只是生命周期的一部分,下面这张图就是maven的整个生命周期。
这个上面就是maven的全部的声明周期,但是我们现在只说一下标注黄色的主要的命名,它的声明周期一般是从左往右,从上到下的。
执行后面的命令的时候都会把前面的命令执行一遍。
其实在这个目录下我们可以看到maven 声明周期的插件
我们借鉴网上https://blog.csdn.net/zhaojianting/article/details/80321488这篇网站来写一下。
我们先来看一张图
可以看到整个执行过程包含了:1.clean 2.resources 3.compile 4.testResources 5.testCompile 6.test 7.jar 8.install;接下来详细说下各个插件的具体的作用;
clean插件是一个独立的阶段,功能是删除当前项目的target目录;这个自己也可以测试下,执行之后就是把target目录删除了而已;
resources插件的功能是把src/main/resources目录的文件拷贝到target/classes目录下;如果不存在src/main/resources目录,则不会做任何处理,测试期间,可以创建一个resources目录,里面添加个1.txt文件,然后执行resources插件,结果如图所示
resource插件的功能就是把项目需要的配置文件拷贝到指定的目当,默认是拷贝src\main\resources目录下的件到classes目录下,当然可以自己来配置源目录和输出目录。resources插件一般不单独执行,complie插件执行时会先调用resources插件。
compile插件执行时,会先执行resources插件,主要的作用就是把src/main/java代码编译成字节码生成class文件,输出到targe/classes目录下;执行效果如图
类似于resources和compile,只不过这两个类主要用于对单元测试的资源文件和代码进行编译;生成的文件位于target/test-classes下面;
有时候可以使用mvn -Dmaven.test.skip=true 跳过该步骤
这个插件是把class文件,resources文件打包成一个jar包,依赖包是不在里面包含的;常用的打包的插件有maven-jar-plugin、maven-assembly-plugin、maven-shade-plugin三种;生成的jar包位于target目录下;
install是把构建好的artifact部署到本地仓库中;这样本地的其他项目依赖于本项目的jar时可以直接从本地仓库去获取,而不用到远端的私服上去下载;
deploy是将本地的jar部署到远端的仓库;需要在maven的setting.xml中配置私服的用户名和密码;还需要再pom.xml做配置;
<distributionManagement> <repository> <id>releases</id> <name>Internal Releases</name> <url>http://localhost:8081/nexus/content/repositories/thirdparty</url> </repository> <snapshotRepository> <id>releases</id> <name>Internal Releases</name> <url>http://localhost:8081/nexus/content/repositories/thirdparty</url> </snapshotRepository> </distributionManagement>
mvn clean package依次执行了clean、resources、compile、testResources、testCompile、test、jar(打包)等7个阶段。
mvn clean install依次执行了clean、resources、compile、testResources、testCompile、test、jar(打包)、install等8个阶段。
mvn clean deploy依次执行了clean、resources、compile、testResources、testCompile、test、jar(打包)、install、deploy等9个阶段。
由上面的分析可知主要区别如下,
package命令完成了项目编译、单元测试、打包功能,但没有把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库
install命令完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库,但没有布署到远程maven私服仓库
deploy命令完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库
标签:aliyun space 统一 you txt web 包冲突 gre 网站
原文地址:https://www.cnblogs.com/qingruihappy/p/10398649.html