Maven common commands

  1. Create Maven’s normal Java project:

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

  1. Create Maven’s Web project:

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

  1. Build maven project skeleton in reverse:

mvn archetype:generate

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

mvn archetype:create -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.ryanote -Dartifact=common If you still use MVN, you are out Archetype: Generate, it makes the boring business of building a project more personal. You don’t need to memorize archetypeArtifactId anymore. Just type archetype:generate and the rest is “multiple choice”.

CMD steps:

Abbreviation:

MVN archetype: generate-dgroupid =otowa.user. dao-dartifactid = user-dao-dversion = 0.01-snapshot

  1. Compile source code:mvn compile
  2. Compile the test code:mvn test-compile
  3. Run tests:mvn test
  4. Produce site:mvn site
  5. Packaging:mvn package
  6. Install jar in local Repository:mvn install
  7. Clear generated items:mvn clean
  8. Generate eclipse project:mvn eclipse:eclipse
  9. Generate idea project:mvn idea:idea
  10. Using the goal command in combination, such as packing without testing:mvn -Dtest package
  11. Compile test content:mvn test-compile
  12. Jar package only:mvn jar:jar
  13. Test only without compiling, and do not test compiling:mvn test -skipping compile -skipping test-compile

– Skipping can also be used with other combination commands. Clear some system Settings for Eclipse: MVN Eclipse :clean 18. MVN Dependency: List 19. Deploy to a private server: MVN deploy 20. Forcibly checks updates. Because the update policy for snapshot versions (updates several times a day and at intervals) exists, you can run the MVN clean install -u command to forcibly update snapshots. MVN source:jar or MVN source:jar-no-fork

The differences between COMPILE, INSTALL, and deploy are different

  1. MVN compile, compile class files
  2. MVN install, including MVN compile, MVN package, and then upload to the local repository
  3. MVN deploy contains MVN install and then uploads to the private server

Second, other instructions

  A typical use case is to download the code to the native machine via CVS or SVN, and then execute MVN Eclipse: Eclipse generates the Ecllipse project file and imports it into Eclipse. After modifying the code, run MVN compile or MVN test. You can also download the Eclipse maven plug-in.

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 be 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 the application needs, such as XDoclet:

mvn generate-sources

10. Use the Describe target of the Maven help plugin to output information about the Maven Help plugin:

mvn help:describe -Dplugin=help

11. Print the complete target column with parameters using the Help plugin:

mvn help:describe -Dplugin=help -Dfull

12. Get information about a single target and set moJO parameters and Plugin parameters. This command lists all the information about the compile target of the Compiler plug-in:

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

13. List all the targets available for Maven Exec plugins:

mvn help:describe -Dplugin=exec -Dfull

14. Look at this “effective” POM, which exposes Maven’s default Settings:

mvn help:effective-pom

15. To see the full dependency trail, including those artifacts that were rejected for inclusion due to conflicts or other reasons, open Maven’s debug flag and run:

mvn install -X

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

mvn install -Dmaven.test.skip=true

The Maven Assembly plugin is a plugin for creating distributions specific to your application:

mvn install assembly:assembly

18. Web project to generate Wtp plug-in:

MVN - Dwtpversion = 1.0 eclipse: eclipse

19. Clear configuration information for Eclipse project (Web project) :

MVN - Dwtpversion = 1.0 eclipse: the clean

20. Converting a project to an Eclipse project:

mvn eclipse:eclipse

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

MVN exec: java-dexec. mainClass="***.Main" MVN exec: Java -dexec. mainClass="***.Main" -dexec. args="arg0 arg1 arg2" mvn exec:java -Dexec.mainClass="***.Main" -Dexec.classpathScope=runtime

Print a list of resolved dependencies:

mvn dependency:resolve

23. Print the entire dependency tree:

mvn dependency:tree

Use multiple repositories in your application

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

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

Three, additional

mvn help:describe

If you’ve ever had trouble remembering goals for a plugin, if you’ve ever had trouble remembering parameters for a goal, try this command. It’ll tell you everything.

-dplugin =pluginName 2. -dgoal (or -dmojo)=goalName: Used with -dplugin, it lists the goal information of a plugin.

If not, you can also add -ddetail.(Note: a plugin is also considered a “Mojo”)

MVN help:describe -Dplugin=help -Dmojo=describe

mvn tomcat:run

With Maven, you no longer need to use Tomcat in Eclipse to run web projects (it’s common to find out-of-sync updates), just run the MVN tomat:run command in the appropriate directory and run it in your browser. If you want more customization, add the following configuration to the POM.xml file:

01 02 03 04 org.codehaus.mojo 05 tomcat-maven-plugin 06 07 /web 08 9090 09 10 11 12

The following are commonly used:

1>. Skip tests: -dmaven.test.skip (=true)

2>. Specify the port: -dmaven.tomcat. port=9090

3 >. Ignore the test failure: – Dmaven. Test. Failure. Ignore = true, of course, if you have other related project updates, be sure to run the project root directory MVN clean install to perform update, then run the MVN Tomcat :run takes effect.

mvnDebug tomcat:run

This command is mainly used for remote tests. It listens on port 8000 for remote tests. When you open remote tests in Eclipse, it will run, set breakpoints, debug, everything is so simple. The same parameters mentioned above apply here.

mvn dependency:sources

With the name, you don’t have to hunt around for the source code. Run it and you’ll have the source code for all the JAR packages your project depends on