maven结构配置

1.maven目录结构:

project:

├───src
│   ├───main
│   │   └───java
│   │       └───cnblogs
│   └───test
│       └───java
│           └───cnblogs
└───target
│   └───test
│       └───java
│           └───cnblogs
└───pom.xml

2. maven命令行:

mvn -v 查看maven版本号

mvn compile 编译

mvn test 测试

mvn package 打包

mvn clean 删除target

mvn install 安装jar包(依赖)到本地仓库

3.maven创建目录的两种方式

  • archetype:generate 按照提示进行选择
  • archetype:generate -DgroupId=组织名(公司网址的反写+项目名)

            -DartifactId=项目名-模块名

            -Dversion=版本号

            -Dpackage=代码素偶存在包的包名

4.完整项目构建过程包括:

      清理(clean),编译(complie),测试(test),打包(package),集成测试,验证,部署

5.maven的生命周期:

 clean 清理项目,default 构建项目 site 生成项目站点

 clean:

      pre-clean 执行清理前的工作

      clean 清理上一次构建生成的所有文件

      post-clean 执行清理后的文件

  default(最核心):

       compile,test,package,install

  site:

      pre-site 在生成项目站点前的工作

      site 生成项目的站点文档

      post-site 在生成项目站点后要完成的工作

      site-deploy 发布生成的站点到服务器上

 6.maven插件结构

 pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>   
            <executions>
                <excution>    
                    <phase>package</phase>
                    <goals>
                       <goal>jar-no-fork</goal>
                    </goals>    
                </excution>
            </excutions>
        </plugin>
    </plugins>
</build>

 pom.xml常用元素

坐标:

<groupId>反写的网址+项目名</groupId>

<artifactId>项目名-模块名</artifactId>

<version></version>

<!-- 第一个0表示大版本号,第二个0表示分支版本号,第三个0表示小版本号,

  0.0.1SNAPSHOT

  snapshot快照,alpha内部测试版本,beta公测版本,release稳定版本,GA正式发布版本

-->

<package></package>

<!--默认是jar,可以设置为war,zip,pom  -->

<name></name><!-- 项目名称 -->

<url></url><!--项目地址-->

<description></description><!-- 项目描述 -->

<develops></develops>

<licenses></licenses>

<organization></organization>

依赖:

<dependencies>
        <dependency>
            <groupId></groupId>
            <artifactId></artifactId>
            <version></version>
            <type></type>
            <scope>test</scope> <!--依赖范围 -->
            <optional></optional><!--设置依赖是否可选true||false -->
            <exclusions><!--排除依赖列表 -->
                <exclusion>
                    <groupId></groupId>
                    <artifactId></artifactId>
                </exclusion>
            </exclusions>  
        <dependency>
<dependencies>

 依赖管理:

<dependencyManagement>
        <dependencies>
            <dependency></dependency>
        </dependencies>
</dependencyManagement>
<build>
    <plugins><!--插件列表 -->
        <plugin>
            <groupId></groupId>
            <artifactId></artifactId>
            <version></version>
        </plugin>
    </plugins>
</build>

设置setting.xml

<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>D:/2016/apache-maven-3.3.9/repo</localRepository>

<profiles>

<profile>
    <id>jdk-1.7</id>
    <activation>
        <activateByDefault>true</activateByDefault>
        <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>


</settings>

 

      

stay hungry,stay foolish.
原文地址:https://www.cnblogs.com/ifree-x/p/maven.html