Maven Onboarding Learning

1. What is Maven?

concept:

Maven is a framework. It can be used as dependency management tool, build tool.

It can manage the size of the jar package, the source of the jar package, and the dependencies between the jar packages.

Its purpose is to manage large-scale jar packages and perform build operations out of the IDE environment.

Specific use:

 Working Mechanism:

To learn Maven, you must understand the construction process of the project:

Maven's action path:

Two, configure Maven

1. Download Maven from the official website

Note that the distinction is wrong!

 2. You can use it after decompression

3. Specify the local warehouse location

4. Configure the mirror warehouse provided by Alibaba Cloud

 

 5. Configure the basic JDK version of the Maven project

 6. Configure environment variables

There are four steps: Check JAVA_HOME to see if the JDK is configured.

Check Maven_HOME to see if Maven is configured.

 

 Finally, type mvn -v to test.

3. Maven coordinates

It is similar to the spatial coordinate value in mathematics. X, Y, Z 

basic concept:

 

 

Four, Maven create project

The basic steps:

 The command for Maven to create a project is: mvn archetype:generate

Creating a project requires specifying two coordinates. That is, the three coordinates of Maven need to be specified manually. As shown below:

 2. Enter this workspace.

Interpret the POM.xml file:

The most important thing is the dependency tag.

 

Five, the core concept of Maven: POM

basic concept:

The core of Maven is the POM file. Project object model. You need to use Maven commands to operate. Similar to the previous command to create a project. The following commands are more detailed. Specifically implement the Maven project.

Realize the operation of Maven project: 

It is not the same as creating a Maven project. These commands are: clean operation, compile operation, test operation, packaging operation, installation operation.

Note: It must be after creating the project! ! ! Then enter this workspace! It is the workspace, which is the directory where the pom.xml file is located. Not into the pom.xml file!

 

 

 

 

 summary:

The difference between using Maven to create a project and using the mvn install command.

Using Maven to create a project is to define the working directory and workspace at the beginning.

Using the mvn install command is to import the custom local jar package into the local warehouse, so that it can be directly referenced in the pom through dependency.

The mvn install command is used to obtain other people's open source projects in git, and then use this command to store other people's projects in their own local warehouse. Doesn't seem to work without this command? There will be a lot of red errors.

There is another explanation: it is to import your own project into your own local warehouse. In this way, in other projects, you can directly call the created method from your own local warehouse.

6. Create a Maven version of the web project

The method used earlier is to create a Java project.

Basic usage:

Need to memorize the command. But it will be more convenient in IDEA.

 

 The basic steps:

If there is something unclear, I suggest you go to Baidu yourself.

 

 Summary: The general steps are: use the maven command to create a web project. Then create the servlet class. Register the servlet class in the web.xml file. Write JSP web pages. Configure the dependency on the servlet class in the POM.xml file. Package the web project. Finally, deploy the war package to the server (Tomcat) to run.

Deployment package: put the packaged war package in the webapps under the tomcat directory.

7. Let web projects depend on Java projects

basic concept:

The basic steps:

I can't understand the following video. It needs precipitation and practical training. Pause.


First training:

The goal at this stage is to use maven project proficiently, create Java project and create JavaWeb project.

Then when using maven to create a Java project, also use IDEA to create a Java project.

Encountered problems:

Create a Java project:

Manually create a Java project:

Manually create Maven's Java project: mvn archetype:generate.

   Then pass mvn test. Test compilation. An error was reported during compilation. The problem that arises is: invalid found version, error in setting.xml file. The reason is that the version name set by jdk is 11.0.11. After changing to 11, it was solved.

IDEA tools create Java projects:

The first creates an empty project, in this case a Java program. But it's not a maven project. The output in this case is the out file .

Only the compilation of the Maven project is the target file .

The second one is created by maven. But can't find Java project. There are only maven_web projects at most.

Unknown, need to find out how to create the data. Create a Maven Java project through IDEA.

This article is very good, and it solves the problem of using IDEA to create a Maven Java project. The original version number should be:

1.0-SANPSHOT

 I just didn't know how to write the version number wrong before. (Through the experiment, the first method is not possible, or use the second method to create a Java project!!!) And this article also talks about the second method to solve the problem of creating a Java project.

Maven and Git_git pom_Follower 1997's Blog-CSDN Blog

The role of the Maven operation command:

 As we can see, it creates files in the maven repository. Moreover, a jar package will also be created in this project, and its location is under the target directory in this project.

It will not deploy the jar package to the local warehouse and the remote private server warehouse if the package is obtained by searching the information. The following figure:

As for the concept of the warehouse, when we were learning github, we knew what the role of the warehouse was. So I come to a conclusion. For example: when we use github to get an IDEA project, if it is a maven project. We need to use the mvn install command to deploy it to the local mvn warehouse. Otherwise it will complain about missing various packages.

The new computer encountered some errors when using the database: for example, the mysql connection was not opened. Result, enter mysql -u root -p. Verify that there is no localhost.


To run the project tomorrow, the two software Xshell 5 and Xftp 5 also need to learn.

1. Scope of test dependencies

The problem is, I don't know what this test dependency means. This part can only be skipped first.

Guess you like

Origin blog.csdn.net/qq_55928086/article/details/132145323