Deep understanding of building and introducing Maven environments, and deep understanding of building maven
Maven is a Java tool for project management. In JavaEE, we can use Maven to conveniently manage projects in team collaboration. Now we are learning the JavaEE framework and can use Maven to manage the library, it is effective and convenient for other personnel in the team.
The project has been completed recently. I have had a lot of time to review the previous knowledge for better use in the future. I will start with building maven and then build the following SSH + mybatis framework, finished learning about Hadoop distributed.
Configure the environment variables of your computer before installation.
1. Configure the maven Environment
: Http://maven.apache.org/download.cgi (Windows download (Binary zip)
Decompress maven and configure the environment variable. Open: Computer ------ System Properties ------ advanced system settings ------ Environment Variables
Create M2_HOME with System Variables
Variable value E: \ apache-maven-3.2.5 (maven decompression location)
Add
; % M2_HOME % \ bin ---- add the number after path;
Start cmd and enter mvm-v to view the version.
2. Modify the location of the local repository
The default local repository location of maven is/. m2/repository in the current user directory. We can configure it to another disk.
E:/m2/repository is configured here.
Open cmd and run a simple maven command: mvn help: system to download the relevant maven information.
3. Configure the maven plug-in of Eclipse
1. Open Eclipse and select help ---- Install New Software ------ add
Name: m2e
Location: http://m2eclipse.sonatype.org/sites/m2e
Download the package and decompress it. Copy the content in the features and plugins folders to the features and plugins corresponding to Eclipse, and restart.
2. Configure the user range setting. xml
% M2_HOME %/conf/setting. xml is a global setting, and all users on this computer will be affected, so % M2_HOME %/conf/setting. copy the xml file to the F:/m2 folder in the repository configuration above.
3. Set MAVEN_OPTS Environment Variables
When the project is too large, an OutOfMemoryError exception may occur. Therefore, you need to modify the running content by using either of the following methods:
1) Add set MAVEN_OPTS =-Xms125m-Xmx512m to maven bin/mvn. bat.
2) Add the MAVEN_OPTS variable value to the Environment Variable-Xms125m-Xmx512m
4. Configure Eclipse
In Window -- Preferences -- Maven
Installations: deselect the default maven directory installed by add.
Select setting. xml in the local repository configuration in user Settings, for example, my E: \ m2 \ settings. xml
Click application.
4. Create a Maven Project
Select create Maven project in Eclipse and select work environment
1. Select the filter to be created as follows:
2. Fill in the maven project coordinate information
We can see that the maven structure has been generated for the project.
V. Introduction to Maven
The generated maven pom. xml file is shown below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.andy</groupId> <artifactId>redis_demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>redis_demo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
The tag has the following meanings:
Project: top-level element in the pom. xml file;
ModelVersion: Specifies the version of the object model used by POM. This value is rarely changed.
GroupId: Specifies the unique identifier of the organization or group that creates the project. GroupId is a key identifier of a project. Typically, it is defined by a fully qualified name of an organization. For example, org. apache. maven. plugins is the groupId specified by all Maven plug-in projects.
ArtifactId: specifies the basic name of the main product generated by this project. The main product of a project is usually a JAR file. Second, like the source code package, artifactId is usually used as part of the final name. The typical product name uses this format: <artifactId>-<version>. <extension> (for example: myapp-1.0.jar ).
Version: the version number of the project. Maven helps you manage versions. you can often see the SNAPSHOT version, indicating that the project is in the development stage.
Name: Project display name, which is usually used in maven documents.
Url: Specifies the project site, which is usually used in maven documents.
Description: describes this project, which is usually used in maven documents.
Properties: configuration information in the pom file. global variables can be configured.
Dependencies: dependency configuration set, which can add the required jar dependency information
For example, we need to add jedis jar, you can search http://mvnrepository.com/
Add the corresponding dependency to the dependencies Tag:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.6.2</version> </dependency>
Vi. maven-related commands
Mvn archetype: create a Maven Project
Mvn compile: compile the source code (to the target folder)
Mvn test-compile: compile the test code
Mvn test: run the unit test in the application.
Mvn site: the website that generates project-related information
Mvn clean: Clear the generated results in the target directory (clear the data in the default target folder)
Mvn package: Project Packaging
Mvn install: install the packaged package in the local repository so that its tower project can call
Mvn eclipse: generate an Eclipse project file
Mvn-Dmaven. test. skip = true: Ignore test document compilation
Cargo: deploy to private server
Of course, these commands can be used together, for example
Create a jar package and install the package to other applications (clean, compile, package, and install jar)
Create a war package and deploy the clean compile package cargo: deploy (clean, compile, package, and install war)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.