MAVEN is used only to manage Java projects and is also developed in Java
Traditional projects because of the management of the package has a lot of problems, so only the birth of Maven:
1. At the beginning of the project, identify the packages that may be used in the project, then download the package, copy and paste it into the project-"Maven just needs to determine the package, and then write the package configuration information in the
2. After the package import is complete, there may be a problem with the package conflict, you need to find the conflict jar in the original jar package, and then delete-"maven only need to delete a node in the Pom.xml configuration file can be;"
3. The original project size may be large, but after using MAVEN, the project size will become very small;
Using Maven we need to understand the following concepts:
The development of a Java project involves several steps:
1. Encoding
2. Compiling
3. Testing
4. Running
5. Packaging
6. Deployment
And Maven can help us do it: compile, test, run, package, deploy, that means we just have to do the coding, and the rest can be given to maven.
Start installing and configuring MAVEN below:
1. Download maven
2. Configure Environment variables
maven_home:d:\software\apache-maven-3.5.3
Add Maven_home to path:%maven_home%\bin;
Test configuration is correct: cmd->mvn-v
Here are a few of Maven's warehouses:
1. Local warehouse, self to maintain
2. Remote Storage: Generally maintained by the company
3. Central Warehouse: Maven Team Maintenance
Below is a project directory structure that uses MAVEN:
Common commands for Maven:
1. Clean: Cleans up compiled files
2. Compile: The file that compiled the home directory
3. Test: Code that compiles and runs the test directory
4. Package: Packaging
5.install: The project is not sent to the local warehouse
The above commands are arranged in the order in which they are used.
Multiple commands can be used simultaneously: MVN clean Package
Let's talk about Maven's configuration steps in Eclipse:
1. Configure the installation path for MAVEN
2. Configure MAVEN's local warehouse address
Here is a MAVEN project created in Eclipse:
1. Create a new MAVEN project
2. Skip configuration to generate the full MAVEN directory structure directly
3. Complete the initial configuration of the Pom configuration file
4. The completed directory is as follows:
5. Handling Red Errors
manually create a Web-inf folder under the WebApp folder, and put a Web. xml file in it
6. Working with compiled versions
Add the following code to the Pom.xml:
<build><!--configured a lot of plugins--><plugins><plugin><groupid>org.apache.maven.plugins</ Groupid><artifactid>maven-compiler-plugin</artifactid><version>3.5.1</version> <configuration><source>1.7</source><target>1.7</target><encoding>UTF-8< /encoding></configuration></plugin></plugins></build>
7. Create a servlet
8. Modify Web. Xml to remove Duplicate code
Add the jar package and add the following code to the Pom.xml:
<dependencies><dependency><groupid>junit</groupid><artifactid>junit</ artifactid><version>4.9</version><scope>test</scope></dependency>< dependency><groupid>javax.servlet</groupid><artifactid>servlet-api</artifactid>< version>2.5</version><scope>provided</scope></dependency><dependency>< groupid>javax.servlet</groupid><artifactid>jsp-api</artifactid><version>2.0</ Version><scope>provided</scope></dependency></dependencies>
You can see that the jar package already exists in the project:
8. Start the project
Right-click Project-"Run as-" maven build
The following is the management of dependencies
1. Add dependencies
Open the view of the MAVEN repository
2. Rebuilding the Index
1. Create Maven project (IBID.)
2. Skip Skeleton (IBID.)
3. Fill in the coordinate information (IBID.)
4. Add Web. xml file (IBID.)
5. Modify the compiled version (IBID.)
Add coordinates Select Dependencies tab click Add
3. Manually enter the dependent configuration properties to be added, select the version
You can see the following content in the Pom.xml file
The MAVEN package management tool for Java package management tools