Maven Introduction and MAVEN installation Introduction 1 Goal 2 Standardization 3 application download installation create MAVEN project 1 Create Project 2 Modify POM Summary
maven profile and maven installation 1. Introduction 1.1 Goals
MAVEN is an automated build tool that is commonly used to build and manage Java projects.
The main purpose of MAVEN is to give developers a comprehensive understanding of the overall project development status in the shortest possible time. Specifically, MAVEN's goal is to make the build process easy to provide a unified build system to provide quality project information provide the best development guidance allow transparent migration to new feature 1.2 standardization
Maven masks Some of the build details, so it's a relief for developers, and it makes the build process much easier.
MAVEN uses the POM model and a series of Plug-ins to build the project (described later in detail), providing a unified build system. Once you're familiar with the projects built with MAVEN, developers are quick to familiarize themselves with other projects that are built with Maven, saving time, and the benefits of standardizing and unifying.
In addition, MAVEN provides a number of useful project information, which is part of the project's Pom file, partly from the project's source code, such as the change log Cross referenced sources mailing lists dependency list generated by source code control Unit test reports that contain code coverage
For the software development process, MAVEN uses the development principles of current best practices to steer a project in the right direction. For example, specifications, execution, and unit test reports are part of a common build using MAVEN. From the test piece, MAVEN takes the best practice of the current test as a Test guide: The test source code remains independent, but the source tree maintains a parallel use of the common test case name to locate and execute test cases so that the test case itself is responsible for its own environment, without relying on a specific build environment
MAVEN also recommends a default directory structure, so that if the developer is familiar with Maven, it's easy to get started with other projects that are built with Maven. 1.3 Application
Maven is an open source project under the Apache Software Foundation and is widely used for the automated construction of large, complex Java projects as a force-giving tool. So learning to use MAVEN to automate the building of Java projects is essential for students who are interested in Java development. 2 Download Installation
For Windows Download installation is simpler:
Download the file to local decompression via a link, and then add the address of the Bin folder to the environment variable.
Test installation: Open cmd, run
Mvn-v
You can see if the installation configuration succeeded.
For other platforms to install the way, you can refer to the official website of the guide. 3 Creating the MAVEN project 3.1 Creating a project
With Maven installed, create a new MAVEN project.
Some MAVEN commands are involved, but because the MAVEN commands and Maven Plug-ins need to be opened in one or several more details, the commands involved in the new MAVEN project can now be taken into account, with a preliminary impression. Under the appropriate folder, run the
MVN archetype:generate
Choose Org.apache.maven.archetypes:maven-achetype-quickstart, which is 7.
After that, Maven generates a project for us in accordance with the fixed file structure template, the engineering directory structure is as follows:
Demo
SRC Main
Java com
Company Demo
App.java Test
Java com
Company Demo
Apptest.java Pom.xml
Since then, the QuickStart template for Maven has been successfully created with an empty project. 3.2 modifying Pom
Add Pom.xml as follows:
<build> <plugins> <plugin> <artifactid>maven-compiler-plugin&
Lt;/artifactid> <version>3.1</version> <configuration> <verbose>true</verbose> <fork>true</fork> <execut
Able>${java_home}</executable> </configuration> <executions> <execution> <id>default-compile</id> <pha Se>compile</phase> <goals> <goal>compile</goal
> </goals> </execution> <execution> <id>default-testCompile</id> <phase>test-compile</phas
E> <goals> <goal>testCompile</goal> </goals>
;
</execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-shade-plugin</arti Factid> <version>1.2.1</version> <executions>
;execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <config
Uration> <transformers> <transformer
implementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" > <mainClass>com.company.demo.App</mainClass> </transformer> </transformers> </configuration> </e
xecution> </executions> </plugin> </plugins> </build>
The pom.xml above is a configuration specification file that automates the construction of the entire project, so it looks cumbersome, without a detailed explanation, followed by a detailed description of Pom.xml.
The above configuration is mainly configured with two: compiled source of JDK path program packaging generated into JAR Package portal (main Class)
And then run the command
MVN Verify
In this way, we have successfully configured MAVEN how to automate the build, and then compiled and packaged to generate an executable jar package.
Location of jar Packages Demo\target\demo-1.jar
Execute command
Java-jar Demo-1.jar
You can see the output
Hello world!
4 Summary
This article briefly describes what Maven is and how Maven uses it in the actual software development process, then demonstrates how to download, install, configure MAVEN, and finally create an empty template project with some basic MAVEN commands. and packaged it into an executable jar package.
MAVEN's capabilities are more than just compiling and packaging a Java project, the use of more Maven features, the usage and implications of some basic MAVEN commands, and the MAVEN plug-in system and Pom are described later.