Create and run the maven project

Create and run Maven project

Continued from above: Introduction to maven, download configuration

The following download links are commonly used maven repositories, just download and unzip it to your own warehouse folder (the default location of the warehouse folder is: C:\User\Username\.m2\repository):

Maven common warehouse download

One, create a Maven project under cmd

  1. Open the command line window in the folder where you want to create the maven project (or win+r, enter cmd and press Enter to display the command line window, and cd to the project directory)

  2. Make sure that there is no folder with the same name as the project to be created in the project directory. Take j2se as an example for the project name:

    mvn archetype:generate -DgroupId=com.how2java -DartifactId=j2se -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    

    The explanation is as follows:

    archetype: generate means creating projects
    -DgroupId Project Package name: com.how2java
    -DartifactId Project Name: J2SE
    DarchetypeArtifactId Project Type: Maven-archetype-QuickStart
    -DinteractiveMode: false indicates that you gave parameters, do not enter one by one

    If the operation is successful, the word BUILD SUCCESS will appear, as shown in the figure below:

    mvn

  3. Enter the project directory and execute mvn package:

    Example: execute mvn package command after cd j2se

    mvn package

  4. Run the project:

    The execution command is as follows:

    java -cp target/j2se-1.0-SNAPSHOT.jar com.how2java.App
    

    The App is the Java code of HelloWorld built into the newly created maven project.

    The results of the implementation are:

    java -cp Hello World

Two, configure Maven in Eclipse

The Eclipse EE version has integrated Maven, so you only need to configure the relevant path.

  1. Configure Maven path

    Menu->Window->Preferences->Maven->Installations-> Specify d:\software\apache-maven-3.6.1

    Insert picture description here

    (Because I have already added it before, so I will report the existing error of the maven.)

  2. Set the warehouse path:

    菜单->Window->Preferences->Maven->User Settings->

    Among them, Global Settings and User Settings both use the following configurations, which vary from person to person:

    D:\software\apache-maven-3.5.0\conf\settings.xml
    

    In addition, make sure that the local Repository path is the maven repository path, which varies from person to person:

    d:/maven/repository
    

    Insert picture description here

At this point, Maven in Eclipse is configured and you can start to create and run maven projects.

Guess you like

Origin blog.csdn.net/weixin_40849588/article/details/93253867