The Maven utility command for the program must change course

Source: Internet
Author: User


summarize some of the more MAVEN commands I've used in my work.1. MVN Clean This command cleans up the target directory that maven compiles.extension: We generally recommend a <packaging>pom</packaging> parent project when we are building a directory structure, so we run MVN in the parent directory The clean command cleans up target for all sub-projects.directory structure Examples:...... <groupId>com.tgb.lk</groupId><artifactId>lk-example-parent</artifactId><packaging>pom</packaging><modules><module>, .... /lk-example-core</module><module>, .... /lk-example-web</module><module>, .... /lk-example-api</module><module>, .... /lk-example-common</module></modules>......
2.MVN Package This command can be used to play the installation packages (Jar,war,ear, etc.), at the time of the build will download the corresponding JAR (note: This does not necessarily associate download Pom, if you want to associate download related POM need to use MVN dependency:tree command)
3.mvn dependency:tree This command shows the reference relationship between the Pom and automatically downloads the relevant pom (note: This command does not necessarily download the jar associated with all references).example of the result of the command:

extension: Running the command directly on the command line is displayed in a black window, it is not easy to find, we can use MVN dependency:tree>1.txt to output the content to a file, which can be found directly in the file.
4.mvn dependency:copy-dependencies This command can be fully associated with the jar directly introduced in the Pom and indirectly introduced into the./target/dependency folder.Extension: We can use the output of this command and combine the MVN dependency:tree to help us resolve the jar version conflict problem.For example (the following error you may often encounter oh ~), our Pom wrote this<dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.3.16.3</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-spring-plugin</artifactId><version>2.3.16.3</version></dependency><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-json-plugin</artifactId><version>2.3.16.3</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.1.2.RELEASE</version></dependency>found debugging always run times wrong, through MVN dependency:copy-dependencies see the referenced jar Spring version has 4.1.2.RELEASE and 3.0.5.RELEASE version


at this point we can conclude that the spring version conflict caused the error, but which jars led to the indirect introduction of the 3.0.5 version? Through MVN Dependency:tree can help us locate the source of the indirect reference, as follows:[INFO] +-Org.apache.struts:struts2-core:jar:2.3.16.3:compile[INFO] | +-Org.freemarker:freemarker:jar:2.3.19:compile[INFO] | +-Ognl:ognl:jar:3.0.6:compile[INFO] |  | \-Javassist:javassist:jar:3.11.0.ga:compile[INFO] | +-Commons-fileupload:commons-fileupload:jar:1.3.1:compile[INFO] | \-Commons-io:commons-io:jar:2.2:compile[INFO] +-Org.apache.struts.xwork:xwork-core:jar:2.3.16.3:compile[INFO] | +-Org.apache.commons:commons-lang3:jar:3.1:compile[INFO] | +-Asm:asm:jar:3.3:compile[INFO] | \-Asm:asm-commons:jar:3.3:compile[INFO] | \-Asm:asm-tree:jar:3.3:compile[INFO] +-Org.javassist:javassist:jar:3.18.2-ga:compile[INFO] +-Org.apache.struts:struts2-spring-plugin:jar:2.3.16.3:compile[INFO] | +-Org.springframework:spring-context:jar:3.0.5.release:compile[INFO] |  | +-Org.springframework:spring-aop:jar:3.0.5.release:compile[INFO] |  |  | \-Aopalliance:aopalliance:jar:1.0:compile[INFO] |  | +-Org.springframework:spring-expression:jar:3.0.5.release:compile[INFO] |  | \-Org.springframework:spring-asm:jar:3.0.5.release:compile[INFO] | \-Org.springframework:spring-web:jar:4.1.2.release:compile[INFO] +-Org.apache.struts:struts2-json-plugin:jar:2.3.16.3:compile[INFO] +-Org.springframework:spring-core:jar:4.1.2.release:compile
through the above results can be analyzed is because org.apache.struts:struts2-spring-plugin:jar:2.3.16.3 this jar indirectly lead to 3.0.5 version, how can solve, three kinds of ideas:1. Include exclusions in POM references, such as <dependency><groupId>org.apache.struts</groupId><artifactId>struts2-spring-plugin</artifactId><exclusions><exclusion><groupId>org.springframework</groupId><artifactId>spring-context</artifactId></exclusion></exclusions></dependency>This will solve the problem that the program does not need this jar, but the Spring-context.jar in this example must be introduced by the program. So consider the 2nd kind2. <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.1.2.RELEASE</version></dependency>
5.mvn dependency:analyze This command allows us to analyze dependencies.

extension: Eclipse because the MAVEN plug-in integration is not very good, some jar indirectly associated with the jar can not be loaded, resulting in Eclipse run error, through this command can help us to find out those jars are code compile must be introduced and you did not declare in the Pom introduced.
for the time being, we'll go ahead and add them later.




The Maven utility command for the program must change course

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.