zoukankan      html  css  js  c++  java
  • maven常用命令

    1. mvn help:describe 你是否因为记不清某个插件有哪些goal而痛苦过,你是否因为想不起某个goal有哪些参数而苦恼,那就试试这个命令吧,它会告诉你一切的. 参数: 1. -Dplugin=pluginName 2. -Dgoal(或-Dmojo)=goalName:与-Dplugin一起使用,它会列出某个插件的goal信息,如果嫌不够详细,同样可以加 -Ddetail.(注:一个插件goal也被认为是一个 “Mojo”) 下面大家就运行mvn help:describe -Dplugin=help -Dmojo=describe感受一下吧!

    mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin

    简化后,以插件的目标前缀替换坐标
    mvn help:describe -Dplugin=compiler
    如果仅描述某个插件目标的信息,可以加上goal参数:
    mvn help:describe -Dplugin=compiler -Dgoal=compile
    输出更详细的信息加上detail参数
    mvn help:describe -Dplugin=compiler -Ddetail
     
    它不需要在项目目录下运行。但是你必须提供你想要描述插件的groupId和artifactId,这个目标比较复杂,包含7种参数{plugin ,mojo,Dcmd,minimal, medium ,output and full }
    Dmoji参数是存放每个阶段的goal信息的,比如compiler阶段有2个goals:complie和testCompile 在查询的时候Dmojo=compile或testCompile
    #mvn help:describe -Dplugin=compiler -Dmojo=compile
     

    2. mvn archetype:generate 你是怎么创建你的maven项目的?是不是像这样:mvn archetype:create -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.ryanote -Dartifact=common,如果你还再用的话,那你就out了,现代人都用mvn archetype:generate了,它将创建项目这件枯燥的事更加人性化,你再也不需要记那么多的archetypeArtifactId,你只需 输入archetype:generate,剩下的就是做”选择题”了.

    3. mvn tomcat:run 用了maven后,你再也不需要用eclipse里的tomcat来运行web项目(实际工作中经常会发现用它会出现不同步更新的情况),只需在对应目录 (如/ryanote)里运行 mvn tomat:run命令,然后就可在浏览器里运行http://localhost:8080/ryanote查看了.如果你想要更多的定制,可以在 pom.xml文件里加下面配置: 01 02 03 04 org.codehaus.mojo 05 tomcat-maven-plugin 06 07 /web 08 9090 09 10 11 12 当然你也可以在命令里加参数来实现特定的功能,下面几个比较常用: 1. 跳过测试:-Dmaven.test.skip(=true) 2. 指定端口:-Dmaven.tomcat.port=9090 3. 忽略测试失败:-Dmaven.test.failure.ignore=true 当然,如果你的其它关联项目有过更新的话,一定要在项目根目录下运行mvn clean install来执行更新,再运行mvn tomcat:run使改动生效.

    4. mvnDebug tomcat:run 这条命令主要用来远程测试,它会监听远程测试用的8000端口,在eclipse里打开远程测试后,它就会跑起来了,设断点,调试,一切都是这么简单.上面提到的那几个参数在这里同样适用.

    5. mvn dependency:sources 故名思义,有了它,你就不用到处找源码了,运行一下,你项目里所依赖的jar包的源码就都有了,即当前项目的pom.xml里的依赖的库的源代码。

    5.1、mvn dependency:resolve -Dclassifier=javadoc    有了它,你就不用到处找java doc了,运行一下,你项目里所依赖的jar包的doc就都有了,即当前项目的pom.xml里的依赖的库的java doc。

    5.2、如果是从maven 工程通过命令行转换到eclipse工程,转换之前(即使用命令 mvn eclipse:eclipse 之前)在pom.xml里加入:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    也可以达到自动下载source code 和 java doc 的目的。

    5.5、mvn dependency:tree -Dincludes=:spring*::        可以查看包含spring关键字的依赖中是否有冲突

    6、mvn help:describe -Dplugin=org.apache.maven.plugins:maven-help-plugin  可以查看help插件的帮助信息。最新版的help插件一共有9个goals,其中最简单的就是help;system,它会打印出所有可用的环境变量和java系统属性。

    help插件9个goals里主要的4个goals分别是:
    help:effective-pom,help:effective-settings,mvn help:active-profiles和mvn help:describe

    help:effective-pom和help:effective-settings最为有用,它们分别打印项目的有效POM和有效 settings,有效POM是指合并了所有父POM(包括Super POM)后的XML,当你不确定POM的某些信息从何而来时,就可以查看有效POM。

    有效settings同理,特别是当你发现自己配置的settings.xml没有生效时,就可以用help:effective-settings来验证。

    mvn help:active-profiles 列出当前项目的活动profile(项目的,用户的,全局的)

    mvn help:describe -Dplugin=help -Ddetail=true -Doutput=/path/to/file
    该命令就是将help插件的完整信息重定向到file文件里,这样比较便于阅读
    Ddetail和Dfull就是显示完整信息的参数,这里不再赘述啦。

    (附:   mvn help:describe -Dcmd=compile 查看complie插件描述和在maven生命周期里的组成)

    7、mvn用命令行制定下载某个依赖文件的命令:

    mvn dependency:get -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.36 -DrepoUrl=http://... -Dtransitive=false

    8、将本地的jar包安装成本地maven 库:

    mvn install:install-file 
      -Dfile=<path-to-file>  
      -DgroupId=<group-id> 
      -DartifactId=<artifact-id> 
      -Dversion=<version> 
      -Dpackaging=<packaging> 
      -DgeneratePom=true
    
    Where: <path-to-file>  the path to the file to load
       <group-id>      the group that the file should be registered under
       <artifact-id>   the artifact name for the file
       <version>       the version of the file
       <packaging>     the packaging of the file e.g. jar

    或者,直接修改 pom.xml,将本地jar依赖直接加进去

    You can add local dependencies directly (as mentioned in build maven project with propriatery libraries included) like this:

    <dependency>
        <groupId>sample</groupId>
        <artifactId>com.sample</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
    </dependency>

     9、怎么分辨 groupId, artifactId 及version

    • groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names.   groupId是将你的项目从世界上所有项目中区分出来的方法,因此需要一个命名规则。它必须遵守包名的规则,也就是说你必须拥有一个域名,在该域名下你可以创建很多子group。

      eg. org.apache.maven, org.apache.commons             他们就是域名

      A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId.        细分groupId的较好方法是依据项目结构而定。也就是说,如果项目是一个多模块项目,推荐在父groupId后面追加一个新的标志名。

      eg. org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting           他们就是在父groupId (域名)后追加了一个新的标志名

    • artifactId is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar you have to take the name of the jar as it's distributed.        artifactId是jar包除去version的名字。 只要你愿意,你可以使用任何小写字母组成的名字,不能带特殊字符。

      eg. maven, commons-math

    • version if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look.

      eg. 2.0, 2.0.1, 1.3.1

    Consider following as for building basic first application:

    groupId

    • com.companyname.project

    artifactId

    • project

    version

    • 0.0.1

     If I were searching for your framework in the Maven repo, I would look for awesome-inhouse-framework-x.y.jar in com.mycompany.awesomeinhouseframework group directory. And I would find it there according to your convention.

    Two simple rules work for me:

    • reverse-domain-packages for groupId (since such are quite unique) with all the constrains regarding java packages names
    • project name as artifactId (keeping in mind that it should be jar-name friendly)

    ==============================

    Maven常用命令: 
    1. 创建Maven的普通java项目: 
       mvn archetype:create 
       -DgroupId=packageName 
       -DartifactId=projectName  
    2. 创建Maven的Web项目:   
        mvn archetype:create 
        -DgroupId=packageName    
        -DartifactId=webappName 
        -DarchetypeArtifactId=maven-archetype-webapp    
    3. 编译源代码: mvn compile 
    4. 编译测试代码:mvn test-compile    
    5. 运行测试:mvn test   
    6. 产生site:mvn site   
    7. 打包:mvn package   
    8. 在本地Repository中安装jar:mvn install 
    9. 清除产生的项目:mvn clean   
    10. 生成eclipse项目:mvn eclipse:eclipse  
    11. 生成idea项目:mvn idea:idea  
    12. 组合使用goal命令,如只打包不测试:mvn -Dtest package   
    13. 编译测试的内容:mvn test-compile  
    14. 只打jar包: mvn jar:jar  
    15. 只测试而不编译,也不测试编译:mvn test -skipping compile -skipping test-compile 
          ( -skipping 的灵活运用,当然也可以用于其他组合命令)  
    16. 清除eclipse的一些系统设置:mvn eclipse:clean 

    17. 打包源码文件: mvn source:jar

    ps:

    一般使用情况是这样,首先通过cvs或svn下载代码到本机,然后执行mvn eclipse:eclipse生成ecllipse项目文件,然后导入到eclipse就行了;修改代码后执行mvn compile或mvn test检验,也可以下载eclipse的maven插件。

    mvn -version/-v               显示版本信息 
    mvn archetype:generate        创建mvn项目 
    mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app   创建mvn项目

    mvn package              生成target目录,编译、测试代码,生成测试报告,生成jar/war文件 
    mvn jetty:run            运行项目于jetty上, 
    mvn compile              编译 
    mvn test                 编译并测试 
    mvn clean                清空生成的文件 
    mvn site                 生成项目相关信息的网站 
    mvn -Dwtpversion=1.0 eclipse:eclipse        生成Wtp插件的Web项目 
    mvn -Dwtpversion=1.0 eclipse:clean          清除Eclipse项目的配置信息(Web项目) 
    mvn eclipse:eclipse                         将项目转化为Eclipse项目

    在应用程序用使用多个存储库 
    <repositories>    
        <repository>      
            <id>Ibiblio</id>      
            <name>Ibiblio</name>      
            <url>http://www.ibiblio.org/maven/</url>    
        </repository>    
        <repository>      
            <id>PlanetMirror</id>      
            <name>Planet Mirror</name>      
            <url>http://public.planetmirror.com/pub/maven/</url>    
        </repository>  
    </repositories>


    mvn deploy:deploy-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:client-0.1.0.jar -DrepositoryId=maven-repository-inner -Durl=ftp://xxxxxxx/opt/maven/repository/


    发布第三方Jar到本地库中:

    mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:client-0.1.0.jar


    -DdownloadSources=true

    -DdownloadJavadocs=true

    mvn -e              显示详细错误 信息. 
    mvn validate        验证工程是否正确,所有需要的资源是否可用。 
    mvn test-compile    编译项目测试代码。 。 
    mvn integration-test     在集成测试可以运行的环境中处理和发布包。 
    mvn verify               运行任何检查,验证包是否有效且达到质量标准。     
    mvn generate-sources     产生应用需要的任何额外的源代码,如xdoclet。

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lifxue/archive/2009/10/14/4662902.aspx

    常用命令: 
    mvn -v 显示版本 
    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 插件构造数据库

    MAVEN项目标准目录结构

    1.标准目录结构:

    src

      -main
          –bin 脚本库
          –java java源代码文件
          –resources 资源库,会自动复制到classes目录里
          –filters 资源过滤文件
          –assembly 组件的描述配置(如何打包)
          –config 配置文件
          –webapp web应用的目录。WEB-INF、css、js等
      -test
          –java 单元测试java源代码文件
          –resources 测试需要用的资源库
          –filters 测试资源过滤库
      -site Site(一些文档)
    target
    LICENSE.txt Project’s license
    README.txt Project’s readme

    工程根目录下就只有src和target两个目录
    target是有存放项目构建后的文件和目录,jar包、war包、编译的class文件等。
    target里的所有内容都是maven构建的时候生成的

    参照:http://breath.iteye.com/blog/1005447

    ++++++++++++++++++++++++++++++++++++++++++++

    Maven项目的标准目录介绍

    Maven提倡使用一个共同的标准目录结构,使开发人员能在熟悉了一个Maven工程后,对其他的Maven工程也能清晰了解。这样做也省去了很多设置的麻烦。

    以下的文档介绍是Maven希望的目录结构,并且也是目录创建工程是采用的目录结构。Maven推荐大家尽可能的遵守这样的目录结构。

    src/main/java

    Application/Library sources

    src/main/resources

    Application/Library resources

    src/main/filters

    Resource filter files

    src/main/assembly

    Assembly descriptors

    src/main/config

    Configuration files

    src/main/webapps

    Web application sources

    src/test/java

    Test sources

    src/test/resources

    Test resources

    src/test/filters

    Test resource filter files

    src/site

    Site

    LICENSE.txt

    Project's license

    README.txt

    Project's readme

    在顶级目录上是工程的描述文件pom.xml(如果使用Ant则还包括其他属性文件,maven.xmlbuild.xml,另外还包括提供给最终用户的文件,如,README.txt, LICENSE.txt等等。

    顶级目录还包括两个子目录:src,target。顶级目录下可能出现的其他目录仅仅是CVS或.svn和其他多模块工程的工程目录,最好不要再有其他目录。

    Target目录是所有工程编译构建的输出目录。

    Src目录包含所有工程的源码文件,配置文件,资源文件等等。它下面的子目录一般包含main(主要的工程源文件),test(测试文件),site(项目站点文件)。

    项目构建的生命周期的介绍

    Maven 2是围绕着构建生命周期概念设计的。这意味着,构建或者发布的过程已经被清晰的定义了。

    当我们使用Maven构建工程时,我们只需要了解几个Maven定义好的命令即可,其他的工作则交给POM来完成。

    以下给出Maven提供的构建生命周期列表:

    validate

    validate the project is correct and all necessary information is available.

    generate-sources

    generate any source code for inclusion in compilation.

    process-sources

    process the source code, for example to filter any values.

    generate-resources

    generate resources for inclusion in the package.

    process-resources

    copy and process the resources into the destination directory, ready for packaging.

    compile

    compile the source code of the project.

    process-classes

    post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.

    generate-test-sources

    generate any test source code for inclusion in compilation.

    process-test-sources

    process the test source code, for example to filter any values.

    generate-test-resources

    create resources for testing.

    process-test-resources

    copy and process the resources into the test destination directory.

    test-compile

    compile the test source code into the test destination directory

    test

    run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.

    package

    take the compiled code and package it in its distributable format, such as a JAR.

    pre-integration-test

    perform actions required before integration tests are executed. This may involve things such as setting up the required environment.

    integration-test

    process and deploy the package if necessary into an environment where integration tests can be run.

    post-integration-test

    perform actions required after integration tests have been executed. This may including cleaning up the environment.

    verify

    run any checks to verify the package is valid and meets quality criteria.

    install

    install the package into the local repository, for use as a dependency in other projects locally.

    deploy

    done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

    因此,当我们构建一个项目时,只需要了解自己希望做什么,然后执行以上对应的生命周期即可。

    例如,我们希望编译我们的工程。在命令行状态下进入到工程的pom.xml文件所在的目录中,使用命令:mvn compile;希望构建打包我们的工程,使用mvn package即可。

     

     

  • 相关阅读:
    ajax上传图片的本质
    牛逼的bootcss之buttons
    PHP实现登录,注册,密码修改
    thinkphp中的session()方法
    微信企业号支付个人php实现
    js判断是否是用微信浏览器打开
    助店宝微信商城登录流程图
    微信网页授权
    微信公众平台模板消息发送接口文档
    微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈
  • 原文地址:https://www.cnblogs.com/welhzh/p/4466501.html
Copyright © 2011-2022 走看看