mvn使用详解

Maven环境变量配置:
      变量名:M2_HOME     变量值:D:\bin\apache-maven-2.2.1   (安装路径)
      在path值后面追加  %M2_HOME%\bin;    (注意要加分号)
测试:
      Mvn –version 

maven常用命令为 :
       mvn archetype:create :创建 Maven 项目
       mvn compile :编译源代码
       mvn test-compile :编译测试代码
       mvn test : 运行应用程序中的单元测试
       mvn site : 生成项目相关信息的网站
       mvn clean :清除目标目录中的生成结果
       mvn package : 依据项目生成 jar 文件
       mvn install :在本地 Repository 中安装 jar
       mvn eclipse:eclipse :生成 Eclipse 项目文件
生成项目
       建一个 JAVA 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=App
       建一个 web 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp
       archetype  是一个内建插件,他的create任务将建立项目骨架
       archetypeArtifactId项目骨架的类型,DartifactId 项目名称
可用项目骨架有:
       maven-archetype-archetype  
       maven-archetype-j2ee-simple
       maven-archetype-mojo
       maven-archetype-portlet
       maven-archetype-profiles 
       maven-archetype-quickstart
       maven-archetype-simple
       maven-archetype-site
       maven-archetype-site-simple, and
       maven-archetype-webapp
------------------------------------------------------------------------------------------
Setting.xml 配置文件
    localRepository:本地库存位置,jar包保存位置,默认${user.dir}/.m2/repository
    offline: true/false,如不想每次编译都去查找远程中心库,就设置为true,前提是已下载好包
    Servers:配置特定的用户
       <servers>
          <server>
            <id/><username/><password/><privatekey/><pssphrase/>
            <filePermissions/><directoryPermissions/><configuration/> 
          </server>
        </servers>
        id:用于匹配distributionManagement库id
        username,password:用于登陆此服务器的用户名和密码
        privateKey,passphrase:设置private Key,及passphrase
        filePermissions,directoryPermissions:访问权限664/775
   mirrosrs:镜像库,用于添加其他库
        <mirrors>
            <miror>
               <id/><name/><url/><mirroOf/>
            </mirror>
        </mirrors>
        id,name:唯一的标志,用来区别镜像
        url:镜像的url
        mirrorOf:此镜像指向的服务id
    Proxies:代理设置,用于无法直接访问中心库的配置
        <proxies>
            <proxy>
               <id/><active/><protocol/><host/><port/><username/><password/><nonProxyHosts/>
            </proxy>
        </proxies>
        id:代理的标志 active:是否激活代理 
        protocol,host,port:protocol://host:port代理
        username,password:用户名密码 nonProxyHosts:不需要代理的host
     repositories和pluginRepositonries定义本地开发库  用于release发布
        <repositories>
            <repository>
                <id/><name/><url/>
                <releases>
                    <enabled/><updatePolicy/><checksumPolicy/>
                </releases>
                <snapshots>
                     <enabled/>
                </snapshots>
                <layout/>
             </repository>
          </repositories>

-----------------------------------------------------------------------------------------------

Pom.xml 配置文件
     在pom.xml中定义jar包版本还有依赖,管理jar文件。
     包括配置文件;开发需要遵循的规则,缺陷管理系统,组织和licenses,项目的依赖性
     groupId:项目或组织唯一标志,并生成项目路径
     artifactId:项目名称  version:项目版本
     packaging:打包的机制,如jar,pom,war....
     maven中继承的定义
         <project>
             <modelVersion/><groupId/><version/><packaging/>
         </project>
         父项目packaging类型需要为pom,用于parent和合成多个项目,子项目为
         <parent>
              <groupId/><artifctId/><version/>
         </parent>
     Modules合成
         <modules>
            <module>tc-dient</moduble>
            <module>tc-server</module>
         </modules>
     build设置:用于编译设置,包括两个主要元素,build,report
         <project>
            <project>
                <build/>
                <profies>
                   <profile>
                      <build/>
                   </profile>
                </profies>
            </profiles>
          </project>
      build-plugin插件
         <project>
            <build>
               .....
               <plugins>
                  <plugin>
                      <groupId/><artifactId/><version/>
                      <extensions/><executions/>
                   </plugin>
               </plugins>
             </build>
          </project>
       extensions:true/false 是否装载插件扩展,默认为false
       inherited:true/false 此插件配置是否应用于poms(继承)
       configuration:指定插件配置
       dependencies:插件需要依赖的包
       executions:用于配置execution目标,一个插件可以有多个目标
       build-resources资源,项目中需要指定的资源如:log4j.properties
           <project>
              <build>
               <resources>
                    <resource>
                        <targetPath/><filtering/><directory/>
                        <includes>
                            <include/>
                         </includes>
                         <excludes>
                             <exclude/>
                         </excludes>
                      </resource>
                </resources>
             <testResources>
                 ...
             </testResources>
                 ....
            </build>
          </project>
          resources:列表,包括所有的资源
          targetPath:指定目标路径,用于放置资源,用于build
          filtering:是否替换资源中属性placehold
          directory:资源所在的位置
          includes:样式,包括资源
          excludes:排除的资源
          testResources:测试资源列表
       dependencies:依赖关系
           <dependencies>
               <dependency>
                   <groupId/><artifactId/><version/>
                   <type/><scope/><optional/>
               </dependency>
           </dependencies>
        groupId,artifactId,version:描述了依赖的项目唯一标志
        使用以下的命令安装:
              mvn install:install-file –Dfile=non-maven-proj.jar –DgroupId=some.group –DartifactId=non-maven-proj –Dversion=1
        创建自己的库,并配置,使用deploy:deploy-file  设置此依赖范围为system,定义一个系统路径。不提倡。
        type:相应的依赖产品包形式,如jar,war
        scope:用于限制相应的依赖范围,包括以下的几种变量:
        compile:默认范围,用于编译
        provided:类似于编译,但支持你期待jdk或者容器提供,类似于classpath
        runtime:在执行时,需要使用
        test:用于test任务时使用
        system:需要外在提供相应得元素。通过systemPath来取得
        systemPath: 仅用于范围为system。提供相应的路径
        optional: 标注可选,当项目自身也是依赖时。用于连续依赖时使用


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值