Maven 使用及其配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Stephen_mu/article/details/88729769

maven:
      pom: project object model
      plugin:  maven具体的功能都是靠插件完成,maven本身很小,很多功能来源于插件。

maven版本和jdk相关版本:
      maven 3.3 require是JDK1.7 or above,Maven 3.2 requires JDK1.6 or above ,while Maven 3.0/3.1 requires JDK1.5 or above.
      

maven环境配置:
      1.需要jdk环境,
      2.需要在path路径下配置bin目录

maven资源库配置:
      1. conf目录下的setting.xml文件里面需要配置资源曾库的路径    
                <localRepository>D:\apache-maven-3.3.9\Repository</localRepository>    
      2.如果公司内网需要特别的代理,则我们还需要配置代理
             

  <proxies>
      <proxy>
         <id>ncs</id>
         <protocol>http</protocol>
         <active>true</active>
         <host>proxy.ncs.com.sg</host>
         <port>8080</port>
         <username>ncs\p1311788</username>
         <password>R@yner`12</password>
             <nonProxyHosts>10.70.*|192.168.*|localhost|ilabs.ncs.com.sg|projectconnect.ncs.com.sg</nonProxyHosts>
      </proxy>
</proxies>      


      3.也可以在配置文件内部配置全局JDK

              <!--全局JDK配置,1.8版本-->
              <profile>    
                  <id>jdk-1.8</id>    
                  <activation>    
                      <activeByDefault>true</activeByDefault>    
                      <jdk>1.8</jdk>    
                  </activation>    
                  <properties>    
                      <maven.compiler.source>1.8</maven.compiler.source>    
                      <maven.compiler.target>1.8</maven.compiler.target>    
                      <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
                  </properties>          
              </profile>


              
maven常用命令
       1.编译 mvn compiler
       2.测试 mvn mvn test  可以以mvn test -Dtest=${类名} //单独运行测试类
              //运行测试(自动运行测试代码),会先对代码自动编译,生成target包和测试报告
       3.清除 mvn clean //清除原来编译的结果
              //会将编译出来的target包删除
       4.打包 mvn package, mvn package -Dmaven.test.skip //打包时不执行测试代码
              //java项目自动打包为jar包, web项目自动打包为war包
              //打出来的包的名称  工程名称(即 artifactID)-版本版本性质.jar(或.war)
             
       5.安装发布 mvn install //将项目打包成构件安装到本地仓库
                 mvn deploy  //发布项目到本地曾库或服务器(例如 tomcat,Jboss)
       

       6.将maven项目 转换为eclipse工程(即可以被eclipse识别)或IDEA项目     
                 转eclipse工程: mvn eclipse:eclipse
                               mvn eclipse:clean //清除eclipse设置信息
                 转IDEA工程: mvn idea:idea
                            mvn idea:clean //清除idea设置信息
 
Maven仓库
        1.网络仓库:
              1.中央仓库: 官方服务器仓库
              2.公司仓库: 公司内部搭建服务器-私服 (可以存放一些公司私有的项目)
        2.本地仓库:
              1.就是自己在安装maven时,配置的那个本地repository(用户缓存从网络仓库下载下来的资源)        
       
       
pom.xml配置解读
        1.packaging 
              jar:表明这是一个java项目
              war:表明这是一个web项目
              pom:表示这是一个依赖的父项目,提供被子项目依赖    


        2.dependency内置参数配置详解
              groupId:   组织ID
              artifactId 项目名
              version    版本号
              type       项目类型,一般默认为jar,若项目依赖为war,则开发人员可以定义此为war
              scope      依赖范围
                  1.compile: 编译需要,打包需要(大多数jar都是这种) 默认值
                  2.provide: 编译需要,不会被打包(servlet,jsp)
                  3.runtime: 编译不需要,打包运行时需要(jdbc驱动)
                  4.test:    参与测试,不会打包(junit)
                  
                            
                      
Maven插件
        maven大部分功能都是靠插件完成的
        1.maven编译插件
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf-8</encoding>
                </configuration>
               </plugin>
         
         2.。。。。。。        

资源依赖:
        <!--maven项目中,资源的依赖-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.tld</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>         

猜你喜欢

转载自blog.csdn.net/Stephen_mu/article/details/88729769
今日推荐