First, the technology required by the current framework
Two, the current technology in the process of development problems
2.1 A project is a project
- If the project is very large, it is not suitable to continue to use package to divide modules. It is better that each module corresponds to a project, which is conducive to division of labor and cooperation.
- With Maven, you can split a project into multiple projects
2.2 The JAR packages required in the project must be manually copied and pasted to the WEB-INF/lib directory
- The problem is that the same JAR files repeatedly appear in different projects, which on the one hand wastes storage space and on the other makes the project bloated
- With Maven, you can just keep the JAR packages in the “repository,” with projects that need to reference the file interface and actually copy the JAR packages over.
The 2.3 JAR package needs to be prepared for us or downloaded from the official website
- There are a variety of jar packages available for download on different technology websites.
- Some technologies are downloaded from the official website using tools such as Maven or SVN.
2.4 Other JARS that a JAR package depends on need to be manually added to the project
- FileUpload FileUpload ->IO component, commons-fileupload-1.3.jar depends on commons-io-2.0.1.jar.
- Dependencies between all jars, programmer self-knowledge, increase learning costs.
- Maven automatically imports dependent JAR packages.
What is Maven
Maven is an automated build tool for the Java platform
- Make->ant->Maven->Gradle
3.1 Building Maven
-
The build process
- Java source files (.java)-> compile -> bytecode files (.class)-> hand over to the JVM for execution
-
The deployment of
- A BS project does not end up running the dynamic WEB itself, but rather the “compiled result” of the dynamic WEB project.
- Dynamic Web Engineering -> Compile, deploy -> Compile results
-
Set up
3.2 Each link in the construction process
- Cleanup: The removal of old class bytecode files from previous compilations in preparation for the next compilation
- Compile: Program Java source programs into class bytecode files
- Test: Automatic test, call junit program
- Report: Results of test program execution
- Package: Dynamic Web project into a WAR package, Java project into a JAR package
- Installation: Maven-specific concept – copy packaged files to a specified location in the repository
- Deploy: Copy the war package produced by the Dynamic Web project to the specified directory in the Servlet container for it to run.
3.3 Installing Maven core programs
- Check the JAVA_HOME environment variable
- Unzip the Maven core program
- Configuring environment Variables
- validation
3.4 Core concepts of Maven
-
The convention directory structure
-
POM
- Pom.xml is the core configuration file of the Maven project
-
coordinates
- Determined by three keys, groupId, artifactId and Version
- The values are company or organization name + project name, module name, and version number
- Coordinates and warehouse path: groupId/artifactId/version/artifactId + version. The jar
-
Rely on
-
Maven resolves dependencies by looking for dependent packages in the local repository
- For our own development of the package, you need to use the MVN install command after installation can enter the warehouse
-
Scope of dependency
-
1 compile
-
Is it valid for the main program — yes
-
Is it valid for the test program – yes
-
Participate in packaging — participate
-
-
2 test
- Valid for main program – invalid
- Is it valid for the test program – yes
- Package or not — No
- Case in point: Junit
-
3 provided
- Is it valid for the main program — yes
- Is it valid for the test program – yes
- Package or not – No, no deployment
- Typical example: servlet-api.jar
-
-
warehouse
- Classification of warehouse
- Local repository: the repository deployed on the current computer
- Remote warehouse
- Private server: built in the LAN, for all Maven projects in the LAN service
- Central repository: Located on the Internet, it serves Maven projects worldwide
- Central warehouse mirror: set up on all continents to share the flow of the central warehouse, reduce the pressure on the central warehouse, and respond to user requests more quickly.
- What’s stored in the repository: The repository is full of Maven projects
- Plugins required by Maven itself
- Jar packages for third-party frameworks or tools
- Maven project that we developed ourselves
- Classification of warehouse
-
Life cycle/plug-in/target
-
inheritance
-
The aggregation
Iv. Maven Project
4.1 Common Directory structure
- 1 Root directory: project name
- SRC directory: source code
- 3 Pom. XML file: the core configuration file of the Maven project
- 4 Main directory: stores the main program
- 5 Test directory: Stores test programs
- 6 Java directory: Java source file
- 7 Resources directory: Stores configuration files of frameworks or other tools
4.2. Why follow the agreed directory structure
- Maven is responsible for the automated build of the project
- Convention > Configuration > Encoding
5. Common Maven commands
5.1 Note: To execute Maven commands related to the build process, you must go to the directory where pom.xml resides
- Related to the build process: compile, test, package……
5.2 Common Commands
- MVN clean: indicates cleaning
- MVN compile: Compiles the main program
- MVN test-compile: compiles test programs
- MVN test: Executes a test
- MVN package: package
- MVN install: installs the package to the repository
- MVN site: indicates the production site
Six, about Maven networking
- Maven’s core program only defines the abstract life cycle, but the specific work must be done by a specific plug-in, and the plug-in itself is not included in Maven’s core program
- When my Maven command requires some plug-ins, the Maven core program first looks for them in the local repository
- 3 Default location of local repository: C:\Users\ ljlory.m2 \repository
- 4 The Maven core program will automatically download the plug-in from the central repository if it is not found in the local repository
- 5 If the extranet cannot be connected, the construction fails
- 6 Change the default location of the local warehouse