Software is a project
We often hear the word engineering in our daily life, such as bridge project, road project, south-to-north water diversion project and so on.
Engineering simply means that employees in various industries summarize laws or methods to make efficient and reliable things in the shortest time, manpower and material resources. We can understand that bridge engineering is actually a highly efficient method that people use to build Bridges based on experience summary and various studies, and of course this method is reusable. We apply this idea of engineering to software, and then we have software engineering.
Software engineering: in order to realize the pipeline-type production of software and to have a standard and engineering method when designing and constructing software, people put forward the concept of software engineering.
This video will help you understand maven’s functions, common commands, how to configure dependencies, as well as important concepts such as dependency scope, dependency transiency, dependency exclusion, lifecycle, inheritance and aggregation. And will walk you through your Maven development projects.
Watch online: www.bilibili.com/video/BV1dp.
Data download: www.bjpowernode.com/javavideo/1…
As an everyday analogy, cooking is a project. I am in a good mood today and want to eat braised pork in brown sauce.
-
Want to buy the meat of that position of what pig, black pork, soil pork and so on, use rock sugar or sponge white sugar, with what brand of soy sauce and so on
-
Go to the wet market to buy all kinds of ingredients.
-
Prepare materials, wash meat, cut pieces, pepper, aniseed, etc
-
Start cooking, meat stew, different time to add pepper, aniseed, rock sugar, soy sauce
-
Let it simmer for a while, check to see if the meat is cooked, taste it, if it’s salty, etc
-
Ready, ready to eat
-
Need to wash dishes, take out the garbage
These tasks are very tedious from start to finish, and each step is time-consuming and laborious. So there are clean vegetables, semi-finished vegetables, take home directly can do, only do 6 or 7 steps can be.
Software development requires compiling code – > developers testing it themselves – > packaging it – > deploying projects to test servers – > testers testing features – > testing to find bugs
Developers need to fix bugs – > developers test the code themselves – > package the code – > deploy the project to the test server – > testers test the functionality – > until it meets the functionality requirements.
This process needs to be repeated many times. Building a project in a large project can be complex, with many configuration files, JAR files, multiple subprojects, and so on. It takes time and effort to complete with manpower, and the efficiency is relatively low. Maven can relieve us from the above work.
Maven is an automated build tool.
Problems existing in traditional project development
A project into a project, resulting in a relatively large project, the use of multiple modules to divide the project;
The project requires a large number of JAR packages, which need to be manually downloaded and imported, and the problem of the duplication of jar packages required by multiple projects;
The jar package required in the project has a version compatibility problem, which needs to be solved manually. The jar packages needed in the project depend on other JAR packages and need to be resolved manually.
What is Maven?
Maven is an automated build tool maintained by the Apache Software Foundation that focuses on project building and dependency management for the Java platform. Maven: Expert, expert. It is pronounced [‘meɪv(ə)n] or [‘mevn].
Maven is the most popular automated build tool. It plays an important role in multi-framework, multi-module integrated development in production environment. Maven is an indispensable tool in the development process of large projects.
Maven can integrate references between multiple projects. We can split any project based on business and hierarchical needs.
Maven provides standardized management of common JAR packages and their versions, and can be automatically downloaded and imported into projects.
Maven automatically resolves jar package version compatibility issues based on the specified version. Maven can automatically download and import other JARS that jar packages depend on.
Similar automated build tools are: Ant, Maven, Gradle.
A build, “build,” is process-oriented (a number of steps from start to finish) and involves multiple parts working together.
Several major parts of the build process
① Clean up: delete the previous compilation results to prepare for recompilation.
② Compilation: Compile Java source programs into bytecode files.
③ Test: Test the key points in the project to ensure the correctness of the key points in the iterative development process.
(4) Report: record and display the test results in a standard format after each test.
⑤ Packaging: Encapsulate a project containing many files into a compressed file for installation or deployment. The Java project corresponds to the JAR package, and the Web project corresponds to the WAR package.
⑥ Installation: In Maven environment, this refers to the installation of the packaged result — jar package or war package into the local repository.
⑦ Deployment: The packaged results are deployed to a remote repository or the WAR package is deployed to run on a server
Maven Core Concepts
Maven’s ability to automate builds is closely related to its internals. Here we look at nine of Maven’s core concepts and see how Maven can automate builds.
(1) the POM
② The agreed directory structure
(3) coordinates
④ Dependency management
⑤ Warehouse management
⑥ Life cycle
⑦ Plugins and goals
Today inheritance
Pet-name ruby polymerization
Maven features
So what’s the difference between Maven and Ant?
Before answering this question, it’s important to emphasize that Maven and Ant address two different aspects of the build problem. Ant provides cross-platform build tasks for Java technology development projects. Maven itself describes the high-level aspects of the project and borrows most of its build tasks from Ant. Therefore, since Maven and Ant represent two very different tools. So I’ll just show you the differences between the equivalent components of the two tools, as shown in Table 1.
Maven is a Project management tool that contains a Project Object Model, a set of standards, a Project Lifecycle, A Dependency Management System and logic to run the plug-in goal defined in the lifecycle phase. When you use Maven, you describe your project with a well-defined project object model, and Maven can then apply crosscutting logic from a set of shared (or custom) plug-ins.
Maven has a life cycle that is called when you run MVN Install. This command tells Maven to perform an orderly series of steps until you reach your specified life cycle. One effect of the traversal lifecycle journey is that Maven runs a number of default plug-in targets that do things like compile and create a JAR file.
In addition, Maven can easily help you manage project reports, generate sites, manage JAR files, and more.
Installing the Maven Environment
Make sure you have a Java environment installed: Maven itself is written in Java, so JDK must be installed.
Check the Java environment variable: echo %JAVA_HOME%
2. Download and unzip the Maven installer:
Maven.apache.org/download.cg…
3. Configure Maven environment variables:
MAVEN_HOME=d:/apache-maven-3.3.9 M2_HOME= D :/apache-maven-3.3.9 path=%MAVEN_HOME%/bin; MAVEN_HOME=d:/apache-maven-3.3.9 path=%MAVEN_HOME%/bin; % or % M2_HOME/bin;
4. Verify whether the installation is successful: MVN -v
The core concepts of Maven
Maven project convention directory structure
The directory structure as agreed in Maven:
Hello
|—src
|—|—main
|—|—|—java
|—|—|—resources
|—|—test
|—|—|—java
|—|—|—resources
|—pom.xml
Description:
- Hello: The root directory, which is the project name
- SRC: source code
- Main: the main program
- Java: Java source code for the main program
- Resources: Configuration files for the main program
- Test: tests the program
- Java: The Java source code of the test program
- Resources: Configuration file for the test program
- Pom. XML: The core configuration file of the Maven project.
In general, the conventional approach is convention > Configuration > code
Maven’s Pom.xml document sets up all aspects of a build project. Maven starts from the pom.xml file and compiles, tests, packages, deploits, and publishes the project according to the project directory of the helper convention.
The first Maven project
Follow these steps to implement your first Maven project, creating directories and class files in the convention recommended by Maven.
-
Create folder Hello in a directory
-
Create a subdirectory SRC in Hello
-
Copying pom.xml to the Hello directory and SRC are placed identically.
-
Go to the SRC directory and create the main, test directory
-
Go to the main directory and create the Java, Resources directory.
-
Go to the Java directory and create the directory com/ bjPowerNode /
Int addNumber(int n1,n2){return n1+n2};
Public static void main(String args[]) {system.out.prinltn (” Hello Manven “); // You can also call the addNumber() method}
-
To enter the Hello directory, run MVN compile
-
Go to the target/classes directory and execute Java
com.bjpowernode.HelloMaven
Pom file
The Project Object Model. Maven abstractions the structure and content of a project into a model, declared in XML files for easy construction and description. Pom.xml is the soul of Maven. So, once the Maven environment is set up, all the learning and manipulation is about POM.xml.
Pom. XML first: