Maven common commands

Maven Library:

http://repo2.maven.org/maven2/

Maven dependency query:

http://mvnrepository.com/

1, Maven common commands:

1. Create Maven's normal Java project:

mvn archetype:create
    -DgroupId=packageName
    -DartifactId=projectName

2. Create Maven's Web project:

mvn archetype:create
    -DgroupId=packageName
    -DartifactId=webappName
    -DarchetypeArtifactId=maven-archetype-webapp

3. Reverse generate the skeleton of maven project:

mvn archetype:generate

How did you create your maven project? Is it like this:

mvn archetype:create -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.ryanote -Dartifact=common

If you still use it, you'll be out. Modern people use mvn archetype:generate, which makes the boring task of creating projects more humanized. You don't need to remember so many archetype artifactids anymore. You just need to enter archetype:generate, and the rest is to do "multiple-choice questions"

cmd steps:

Abbreviation:

mvn archetype:generate -DgroupId=otowa.user.dao -DartifactId=user-dao -Dversion=0.01-SNAPSHOT

4. Compile source code:

mvn compile

5. Compile test code:

mvn test-compile

6. Operation test:

mvn test

7. Generate site:

mvn site

8. Packing:

mvn package

9. Install jar s in the local Repository:

mvn install Example: installing D:\xxx\xx.jar to D:\xx\xxxx

10. Items generated by removal:

mvn clean

11. Generate eclipse project:

mvn eclipse:eclipse

12. Generate idea project:

mvn idea:idea

13. Use the goal command in combination, such as packaging without testing:

mvn -Dtest package

14. Contents of compilation test:

mvn test-compile

15. Only print jar packages:

mvn jar:jar

16. Only test without compilation, nor test compilation:

mvn test -skipping compile -skipping test-compile ( -skipping Of course, it can also be used for other combined commands) 

17. Clear some system settings of eclipse:

mvn eclipse:clean 

18. View the resolved dependencies of the current project:

mvn dependency:list

19. Upload to private server:

mvn deploy

20. Forced check for updates. Due to the existence of the snapshot version update policy (update several times a day, update every other period of time), this command will be used if you want to force updates:

mvn clean install-U

21. Source code packaging:

mvn source:jar or mvn source:jar-no-fork

Differences between mvn compile and mvn install and mvn deploy

  1. mvn compile, compile class files
  2. mvn install, including mvn compile and mvn package, and then upload them to the local warehouse
  3. mvn deploy, including mvn install, and then upload it to the private server

2, PS:

The general usage is as follows: first download the code to the local machine through cvs or svn, then execute mvn eclipse:eclipse generates the ecllipse project file, and then import it into eclipse; After modifying the code, perform mvn compile or mvn test verification, or download the maven plug-in of eclipse.

1. Display version information:

mvn -version/-v

2. Create mvn project:

mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app

3. Generate target directory, compile and test code, generate test report, and generate jar/war file:

mvn package

4. Run the project on jetty:

mvn jetty:run

5. Display detailed error information:

mvn -e

6. Verify whether the project is correct and whether all required resources are available:

mvn validate

7. Process and publish packages in an environment where integration tests can run:

mvn integration-test

8. Run any checks to verify that the package is valid and meets quality standards:

mvn verify

9. Generate any additional source code required by the application, such as xdoclet:

mvn generate-sources

10. Use the describe target of the help plug-in to output the information of the Maven Help plug-in:

mvn help:describe -Dplugin=help

11. Use the Help plug-in to output a complete target column with parameters:

mvn help:describe -Dplugin=help -Dfull

12. Obtain the information of a single target and set mojo parameters and plugin parameters. This command lists all information about the compile target of the Compiler plug-in:

mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull

13. List the available targets of all Maven Exec plug-ins:

mvn help:describe -Dplugin=exec -Dfull

14. Look at this "effective" POM, which exposes Maven's default settings:

mvn help:effective-pom

15. To view the complete dependency trace, including those components that are refused to be introduced due to conflicts or other reasons, open Maven's debugging flag and run:

mvn install -X

16. Add maven.test.skip attribute to any target to skip the test:

mvn install -Dmaven.test.skip=true

17. Build assemble Maven Assembly plug-in is a plug-in used to create your application specific distribution package:

mvn install assembly:assembly

18. Web project for generating Wtp plug-in:

mvn -Dwtpversion=1.0 eclipse:eclipse

19. Clear the configuration information of the Eclipse project (Web project):

mvn -Dwtpversion=1.0 eclipse:clean

20. Convert the project to an Eclipse project:

mvn eclipse:eclipse

21. The MVN exec command can execute the main function in the project:

First, you need to compile java Project: mvn compile
 In the absence of parameters: mvn exec:java -Dexec.mainClass="***.Main"
Parameters present: mvn exec:java -Dexec.mainClass="***.Main" -Dexec.args="arg0 arg1 arg2"
Specify the runtime library: mvn exec:java -Dexec.mainClass="***.Main" -Dexec.classpathScope=runtime

22. Print out the list of resolved dependencies:

mvn dependency:resolve

23. Print the entire dependency tree:

mvn dependency:tree

Use multiple repositories in your application

[](javascript:void(0)😉

<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/

[](javascript:void(0)😉

Publish third-party jars to local libraries

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

3, Attach

mvn help:describe

If you've ever been distressed because you can't remember what goals a plug-in has, and if you're distressed because you can't remember what parameters a goal has, try this command. It will tell you everything

Parameters: 1. - Dplugin = pluginame 2. - dgoal (or - Dmojo)=goalName: used with - Dplugin, it will list the goal information of a plug-in,

If it is not detailed enough, you can also add - Ddetail. (Note: a plug-in goal is also considered a "Mojo")

Now let's run mvn help:describe -Dplugin=help -Dmojo=describe and feel it!

mvn tomcat:run

After using maven, you no longer need to use tomcat in eclipse to run web projects (it is often found that asynchronous updates will occur in actual work). Just run the mvn tomat:run command in the corresponding directory, and then run it in the browser. If you want more customization, you can add the following configuration in the pom.xml file:

01 02 03 04 org.codehaus.mojo 05 Tomcat Maven plugin 06 07 / Web 08 9090 09 10 11 12 of course, you can also add parameters to the command to realize specific functions,

The following are commonly used:

1> . skip test: - Dmaven.test.skip(=true)

2> . specify port: - Dmaven.tomcat.port=9090

3> . ignore test failure: - Dmaven.test.failure.ignore=true. Of course, if your other associated projects have been updated, be sure to run mvn clean install in the project root directory to execute the update, and then run mvn tomcat:run to make the changes take effect

mvnDebug tomcat:run

This command is mainly used for remote testing. It will listen to port 8000 for remote testing. After opening remote testing in eclipse, it will run. Setting breakpoints and debugging are all so simple. The above parameters are also applicable here

mvn dependency:sources

Therefore, with it, you don't have to look for the source code everywhere. Run it, and you will have the source code of the jar package you depend on in your project

Tags: Java Maven jar

Posted on Sun, 31 Oct 2021 12:09:33 -0400 by nocontrol