【转】Maven详细

摘要:
Maven是目前最流行的Java项目管理构建自动化综合工具。开发团队可以自动完成项目的基本工具构建。Maven使用标准目录结构和默认的构建生命周期。Maven使开发人员更容易同时创建报告、检查、构建和测试自动化设置。Maven简化并标准化了项目建设过程。Maven提高了可重用性,并负责建立相关任务。
Maven
maven 中央仓库  网站  https://mvnrepository.com/  全世界 发布到Maven仓库  供用类着使用
maven 本质上下载工具和构建工具
      下载工具  迅雷  只能下载jar包  只能在中央仓库中下载jar包
      构建工具  本身没有构建的功能 依赖他的插件来实现构建
maven 是用java语言编写的
tomcat 也是用java语言编写
java语言编写的程序  不需要安装 解压即可使用 应用程序在bin目录
maven工具 是apache的子项目  tomcat.apache.org
                          commons.apache.org
                          maven.apache.org
java写的程序 与系统环境无关   linux  window    
程序 2种 1.图形界面 2.没有图形界面  控制台运行
mvn install

开发过程中的问题

在开发中经常需要依赖第三方的包,包与包之间存在依赖关系,版本间还有兼容性问题,有时还里要将旧的包升级或降级,当项目复杂到一定程度时包管理变得非常重要。
Maven是当前最受欢迎的Java项目管理构建自动化综合工具。
相同的工具有:
Node.js---------npm
DotNet----------nuget
PHP-------------composer
Python----------pip  
Linux-----------yum
Maven这个单词来自于意第绪语(犹太语),意为知识的积累。![mark]

Maven是什么

Maven提供了开发人员构建一个完整的生命周期框架。开发团队可以自动完成项目的基础工具建设,Maven使用标准的目录结构和默认构建生命周期。Maven让开发人员的工作更轻松,同时创建报表,检查,构建和测试自动化设置。Maven简化和标准化项目建设过程。处理编译,分配,文档,团队协作和其他任务的无缝连接。 Maven增加可重用性并负责建立相关的任务。
每个Java项目的目录结构都没有一个统一的标准,配置文件到处都是,单元测试代码到底应该放在那里也没有一个权威的规范。
因此,我们就要用到Maven(使用Ant也可以,不过编写Ant的xml脚本比较麻烦)----一个项目管理工具。

没有Maven时?

1 如果使用了spring,去spring的官网下载jar包;如果使用hibernate,去hibernate的官网下载Jar包;如果使用Log4j,去log4j的官网下载jar包.....
2 当某些jar包有依赖的时候,还要去下载对应的依赖jar包
3 当jar包依赖有冲突时,不得不一个一个的排查
4 执行构建时,需要使用ant写出很多重复的任务代码
5 当新人加入开发时,需要拷贝大量的jar包,然后重复进行构建
6 当进行测试时,需要一个一个的运行....检查

有了Maven后

1 依赖的管理:仅仅通过jar包的几个属性,就能确定唯一的jar包,在指定的文件pom.xml中,只要写入这些依赖属性,就会自动下载并管理jar包。
2 项目的构建:内置很多的插件与生命周期,支持多种任务,比如校验、编译、测试、打包、部署、发布...
  A.发布  打成jar包 或者是war包
  B.编译  测试  打包   部署   发布
  C.Maven提供一些骨架 帮助我们构建项目  maven项目
    javaFx  java Project   maven-archetype-quickstart
    Web     动态的项目  maven-archetype-webapp
3 项目的知识管理:管理项目相关的其他内容,比如开发者信息,版本等等 

Maven相关网站

官网:http://maven.apache.org/
教程:https://www.yiibai.com/maven/
Maven库:http://repo2.maven.org/maven2/ 
中央仓库资源:
http://mvnrepository.com/
https://search.maven.org/

Maven下载

下载地址:http://maven.apache.org/download.cgi

配置环境变量

添加环境变量MAVEN_HOME,值为apache-maven的安装路径(没有中文)
在Path环境变量的变量值末尾添加%MAVEN_HOME%in;
在cmd输入mvn –version,如果出现maven的版本信息,说明配置成功。

本地仓储配置

如果不配置,默认会在如下位置存放从远程下载到的包:
从中央仓库下载的jar包,都会统一存放到本地仓库中。我们需要配置本地仓库的位置。
打开maven安装目录,打开conf目录下的setting.xml文件。
可以参照下图配置本地仓储位置。
也可以在运行时指定仓库的位置
mvn clean install -Dmaven.repo.local=d:yourpath

中央仓库配置

构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下:
1、从本地资源库中查找并获得依赖包,如果没有,执行第2步。
2、从Maven默认中央仓库中查找并获得依赖包(http://repo1.maven.org/maven2/),如果没有,执行第3步。
3、如果在pom.xml中定义了自定义的远程仓库,那么也会在这里的仓库中进行查找并获得依赖包,如果都没有找到,那么Maven就会抛出异常。
修改默认中央仓库地址 settings.xml
<mirror>
    <id>nexus-aliyun</id>  
    <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>  
    <name>Nexus aliyun</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
</mirror>

常用的中央仓库地址

1、http://www.sonatype.org/nexus/  私服nexus工具使用
2、http://mvnrepository.com/ (推荐)
3、http://repo1.maven.org/maven2
4、http://maven.aliyun.com/nexus/content/groups/public/  阿里云  (强力推荐)
5、http://repo2.maven.org/maven2/ 私服nexus工具使用
6、http://uk.maven.org/maven2/
7、http://repository.jboss.org/nexus/content/groups/public
8、http://maven.oschina.net/content/groups/public/  
9、http://mirrors.ibiblio.org/maven2/
10、http://maven.antelink.com/content/repositories/central/
11、http://nexus.openkoala.org/nexus/content/groups/Koala-release/
12、http://maven.tmatesoft.com/content/groups/public/

完整的配置如下:

<?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.
-->
<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.home}/conf/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>H:InstallFilesjavaKitmavenRes</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->
  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->
  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
<server> 
    <id>admin</id> 
    <username>admin</username> 
    <password>admin</password>
</server>
</servers>
  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  <mirror>
    <id>nexus-aliyun</id>  
    <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>  
    <name>Nexus aliyun</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
  </mirror>
</mirrors>
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>
      <activation>
        <jdk>1.4</jdk>
      </activation>
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
<profile>   
    <id>jdk1.7</id>    
    <activation>   
        <activeByDefault>true</activeByDefault>    
        <jdk>1.7</jdk>   
    </activation>    
    <properties>   
        <maven.compiler.source>1.7</maven.compiler.source>    
        <maven.compiler.target>1.7</maven.compiler.target>    
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>   
    </properties>   
</profile>  
</profiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

完整的项目流程

老师完整演示整个流程
src/main
   java  源代码
   resources 配置文件
   webapp 静态资源+页面
 <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>                                                                                                                        
        <source>1.8</source>                                                                                     
        <target>1.8</target>                                                                                     
    </configuration>        
      </plugin>   
1.不使用任何的开发工具创建Maven项目
2.Maven项目pom.xml详解
3.Maven Plugin插件 常用的一些Plugins
4.聚合工程 

使用骨架

Eclipse 新建Maven Project->选择骨架 quickStart WebApp->groupid artfactid version
IDEA    新建Maven Project->选择骨架 quickStart WebApp->groupid artfactid version
图形化的处理
mvn archetype:generate 进入骨架向导功能
mvn archetype:generate -DgroupId=com.blb -DartifactId=hello2cms -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn archetype:generate -DgroupId=com.blb  -DartifactId=hello3cms  -Dpackage=com.blb  -DarchetypeArtifactId=maven-archetype-webapp   -Dversion=1.0 -DinteractiveMode=No
mvn archetype:generate 
    -DgroupId=组织名称 
    -DartifactId=项目名称 
    -DarchetypeArtifactId=maven-archetype-quickstart  骨架
    -DinteractiveMode=false  是否检查
    -DarchetypeCatalog=http://maven.aliyun.com/nexus/content/groups/public/ 自定义仓库

POM.XML详解

头文件

<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/maven-v4_0_0.xsd">

项目标识

  <groupId>com.blb</groupId>
  <artifactId>okcms</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>okcms</name>
  <url>http://maven.apache.org</url>

全局变量定义

 系统变量
<properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 编码格式
      <maven.compiler.source>1.8</maven.compiler.source>  编译的版本
      <maven.compiler.target>1.8</maven.compiler.target>  编译的版本
  </properties>
 用户自定义变量 前提 多个坐标使用同一个版本的情况
<properties>
      <juit.version>3.8.1</juit.version>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${juit.version2}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

依赖

具体的坐标
<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
</dependency>
scope属性
complier  默认属性
test      只在测试有效 不会打入lib包
provided  只在开发时有效 不会打入lib包 jsp-api/servlet-api Tomcat里面就有 但开发时我们又需要
runtime   会打入到lib包
system    引入第三方包 在本地仓库和中央仓库都没有的情况下  不会打入到lib包
<dependency>
      <groupId>helloUtil</groupId>
      <artifactId>helloUtil</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>d:/路径/jar包</systemPath>
</dependency>

将我们的jar包上传到本地仓库中去

手动上传我们jar包到本地仓库
mvn install:install-file 
 -Dfile=F:	est.jar
 -DgroupId=test
 -DartifactId=test
 -Dversion=0.0.1
 -Dpackaging=jar
classifier的使用
<dependency>  
     <groupId>net.sf.json-lib</groupId>   
     <artifactId>json-lib</artifactId>   
     <version>2.2.2</version>
     <classifier>jdk15</classifier>
</dependency>
exclusions的使用
<!--在前面已经导入到该包  我们了避免重复导入 将某个依赖排除在外-->
<dependency>
      <groupId>net.sf.json-lib</groupId>
      <artifactId>json-lib</artifactId>
      <version>2.4</version>
      <classifier>jdk15</classifier>
      <exclusions>
           <exclusion>
             <groupId>commons-beanutils</groupId>
             <artifactId>commons-beanutils</artifactId>
           </exclusion>
            <exclusion>
              <groupId>commons-collections</groupId>
              <artifactId>commons-collections</artifactId>
            </exclusion>
            <exclusion>
              <groupId>commons-logging</groupId>
              <artifactId>commons-logging</artifactId>
            </exclusion>
      </exclusions>
    </dependency>
optional的使用
应用场景:projectA 依赖projectB,  projectB 依赖projectC时
<dependency>
  <groupId>com.itear.projectC</groupId>
  <artifactId>projectC</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <optional>true</optional>
</dependency>
当projectB的<optional>true</optional>时, projectA中如果没有显式的引入projectC, 则projectA不依赖projectC, 即projectA可以自己选择是否依赖projectC
默认<optional>的值为false, 及子项目必须依赖
type属性
jar  表示当前的项目最终会打成一个jar包
war  表示当前的项目最终会打成一个war包
pom  聚合工程 一般用于团队开发 超过10人的团队 团队开发 4个人一个小组  复杂
多个坐标
 <dependencies>
    <!--单元测试用-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${juit.version2}</version>
      <scope>test</scope>
    </dependency>


    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.11</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.9.3</version>
    </dependency>

</dependencies>
暂时不想他们生效【 一般用于聚合工程】【统一项目jar的版本】
<dependencyManagement>
  <dependencies>
    <!--单元测试用-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${juit.version2}</version>
      <scope>test</scope>
    </dependency>


    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.11</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.9.3</version>
    </dependency>
  </dependencies>
</dependencyManagement>

jetty服务器

<plugins>
            <!-- jetty插件 -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <configuration>
                    <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
                    <scanIntervalSeconds>3</scanIntervalSeconds>
                    <contextPath>/jetty</contextPath>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>4000</port>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>
        </plugins>
mvn jetty:run   

Tomcat服务器

  <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <path>/wp</path>
                    <port>8080</port>
                    <uriEncoding>UTF-8</uriEncoding>
                    <url>http://localhost:8080/manager/html</url>
                    <server>tomcat6</server>
                </configuration>
            </plugin>
            
            
            
<!--tomcat的插件  嵌入式的tomcat服务器 jar包-->
 <plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.2</version>
   <configuration>
     <hostName>localhost</hostName>        <!--   Default: localhost -->
     <port>8080</port>                     <!-- 启动端口 Default:8080 -->
     <path>/</path>   <!-- 访问应用路径  Default: /${project.artifactId}-->
     <uriEncoding>UTF-8</uriEncoding>      <!-- uri编码 Default: ISO-8859-1 -->
   </configuration>
 </plugin>
tomcat:deploy   --部署一个web war包
tomcat:reload   --重新加载web war包
tomcat:start    --启动tomcat
tomcat:stop    --停止tomcat
tomcat:undeploy--停止一个war包
tomcat:run  启动嵌入式tomcat ,并运行当前项目
mvn idea:idea
mvn eclipse:eclipse
mvn -e              显示详细错误 信息. 

mvn validate        验证工程是否正确,所有需要的资源是否可用。
 
mvn test-compile    编译项目测试代码。

mvn integration-test     在集成测试可以运行的环境中处理和发布包。 

mvn verify               运行任何检查,验证包是否有效且达到质量标准。    
 
mvn generate-sources     产生应用需要的任何额外的源代码,如xdoclet。

mvn help:describe -Dplugin=help 使用 help 插件的  describe 目标来输出 Maven Help 插件的信息。 

mvn help:describe -Dplugin=help -Dfull 使用Help 插件输出完整的带有参数的目标列 

mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull 获取单个目标的信息,设置  mojo 参数和  plugin 参数。此命令列出了Compiler 插件的compile 目标的所有信息 

mvn help:describe -Dplugin=exec -Dfull 列出所有 Maven Exec 插件可用的目标 

mvn help:effective-pom 看这个“有效的 (effective)”POM,它暴露了 Maven的默认设置

mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook 创建Maven的普通java项目,在命令行使用Maven Archetype 插件 

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main Exec 插件让我们能够在不往 classpath 载入适当的依赖的情况下,运行这个程序 

mvn dependency:resolve 打印出已解决依赖的列表 

mvn dependency:tree 打印整个依赖树

mvn install -X 想要查看完整的依赖踪迹,包含那些因为冲突或者其它原因而被拒绝引入的构件,打开 Maven 的调试标记运行 

mvn install -Dmaven.test.skip=true 给任何目标添加maven.test.skip 属性就能跳过测试 

mvn install assembly:assembly 构建装配Maven Assembly 插件是一个用来创建你应用程序特有分发包的插件

mvn jetty:run     调用 Jetty 插件的 Run 目标在 Jetty Servlet 容器中启动 web 应用 

mvn compile       编译你的项目 

mvn clean install 删除再编译

mvn hibernate3:hbm2ddl 使用 Hibernate3 插件构造数据库
生命周期阶段描述
mvn validate验证项目是否正确,以及所有为了完整构建必要的信息是否可用
mvn generate-sources生成所有需要包含在编译过程中的源代码
mvn process-sources处理源代码,比如过滤一些值
mvn generate-resources生成所有需要包含在打包过程中的资源文件
mvn process-resources复制并处理资源文件至目标目录,准备打包
mvn compile编译项目的源代码
mvn process-classes后处理编译生成的文件,例如对Java类进行字节码增强(bytecode enhancement)
mvn generate-test-sources生成所有包含在测试编译过程中的测试源码
mvn process-test-sources处理测试源码,比如过滤一些值
mvn generate-test-resources生成测试需要的资源文件
mvn process-test-resources复制并处理测试资源文件至测试目标目录
mvn test-compile编译测试源码至测试目标目录
mvn test使用合适的单元测试框架运行测试。这些测试应该不需要代码被打包或发布
mvn prepare-package在真正的打包之前,执行一些准备打包必要的操作。这通常会产生一个包的展开的处理过的版本(将会在Maven 2.1+中实现)
mvn package将编译好的代码打包成可分发的格式,如JAR,WAR,或者EAR
mvn pre-integration-test执行一些在集成测试运行之前需要的动作。如建立集成测试需要的环境
mvn integration-test如果有必要的话,处理包并发布至集成测试可以运行的环境
mvn post-integration-test执行一些在集成测试运行之后需要的动作。如清理集成测试环境。
mvn verify执行所有检查,验证包是有效的,符合质量规范
mvn install安装包至本地仓库,以备本地的其它项目作为依赖使用
mvn deploy复制最终的包至远程仓库,共享给其它开发人员和项目(通常和一次正式的发布相关)

作者:https://www.cnblogs.com/zhaochengf/

免责声明:文章转载自《【转】Maven详细》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇采用.bat批处理命令快速设置Java环境变量linux操作系统故障处理-ext4文件系统超级块损坏修复下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

pixel和nexus设备安卓9.0/8.1/7.1.x/6.x WiFi和信号图标出现叉x号或者感叹号的消除办 法

在安卓9.0/8.1/8.0/7.1.2里如何消除x号(在老一点点版本是感叹号)呢? 1.首先开启usb调试,然后用数据线连接电脑和手机。 2.然后解决好您的adb驱动问题,具体教程见:http://www.pixcn.cn/thread-1084-1-1.html 3.在电脑开始菜单-运行 输入cmd,打开命令提示符 依次输入下面语句 (以下办法支持安卓...

Nexus 私服无法下载远程 Jar 包问题排查指南

一、前言 前几天线上 ZooKeeper 出了一次不大不小的问题,由于缺少监控报警,导致事发第二天才引起我们的注意,所幸没有造成太大的影响。这起事情也督促我们尽快建立完备的监控体系,目前项目中使用 JavaMelody 监控应用状态,但是缺少实时报警。所以最近团队内部都在调研相关监控工具,初步选型 Sentry。 不过本篇跟 Sentry 其实没啥关系,主...

eclipse中maven插件上传项目jar包到私服

我们知道,每一个公司都会有自己的工具包或公共包。这样的包就能够上传到公司的maven私服,就不用每一个人都去同步开发包了。那么,怎么把本地项目打包并公布到私服呢?依照例如以下步骤就能够轻松完毕。 1.  在setting.xml文件里添加例如以下内容: <servers> <server> <!--...

Centos7.3安装nexus-3.14.0-04

nexus-3.14.0-04的安装       nexus-3.14.0-04-unix.tar.gz             1、下载nexus             2、上传到服务器/root/             3.解压                 tar -zxvf nexus-3.14.0-04-unix.tar.gz...

nexus 3.17.0 做为golang 的包管理工具

nexus 3.17.0 新版本对于go 包管理的支持是基于go mod 的,同时我们也需要一个athens server 然后在nexus 中配置proxy 类型的repo 参考配置 来自官方的配置图 说明 就和上边说的一样,我们需要一个athens server,nexus 对于go mod 的支持就是通过配置proxy到athens server...

nexus在linux上搭建

Maven 仓库的分类:(maven的仓库只有两大类) 1.本地仓库  2.远程仓库,在远程仓库中又分成了3种: 2.1 中央仓库  2.2 私服  2.3 其它公共库 有个maven私服可以很方便地管理我们的jar包和发布构建到远程仓库,本文就介绍了如何在linux下一步步使用nexus搭建maven私服。 私服是架设在局域网的一种特殊的远程仓库,目的是...