MAVEN Installation and Configuration

Source: Internet
Author: User

Download: 1. From the official website http://maven.apache.org download, download down is a compressed package, unzip can. Because MAVEN itself is also implemented in Java.
Directory Structure of 2.Maven
/bin; MAVEN's running directory, including MAVEN's core command MVN, etc.
/boot; MAVEN's Boot Directory
/conf; MAVEN's configuration directory, where Maven's core configuration files are stored
/lib: The jar file required by the MAVEN runtime

Configuration:1. Configure Environment Variables
1) Add Maven_home, specify the root directory of MAVEN
2) Add in path:;%mava_home%\bin
2. Configure the Local warehouse
Open Maven's core profile settings.xml file, specifying the path to the Localrepository local repository
3. Configuring MAVEN in an integrated development environment
1) Configure Maven in eclipse
Wondow-->preferences-->maven
I. Adding the root directory of MAVEN in installations
II. Specify the directory of MAVEN's core profile settings in User settings
2) Configure Maven in idea
File-->settings-->build-->build Tools-->maven
I. Specify the root directory of Maven in the MAVEN home directory configuration options
II. Specify the path to the core profile settings in the User settings file option
Iii. specifying the path to the local warehouse in the locally repository option
VI. Check two override options Warehouse:The 1.Maven warehouse is used to store all class libraries. The envy of all the jars in the development process has been taken from the warehouse.

The 2.Maven warehouse is divided into two main types:
1) Local warehouse
A class library that resides in a dedicated directory in your own native computer
2) Remote Warehouse
A class library stored in a remote host (Apache's central repository is a remote repository)

3. Search Order of warehouses
When you make a dependency on a class library in a project, look it up from the local repository, and if the local repository has the required jar, it will be directly dependent on the local repository, and if not, it will be looked up in the remote repository and then downloaded to the local repository, which is fetched directly from the local repository the next time. 1. Create a MAVEN project: 1) Create a MAVEN project in Eclipse File-->new-->maven Project Create a new Maven project (tick create a simple project), click Next, fill in the corresponding Gav coordinate information and package the way, then click Finish.2) Create a MAVEN project in ideadirectory structure for 2.Maven projectsSrc/main/java Java source code src/main/resources for storing the required resource files and configuration files Src/test/java for storing the written unit test source code src/test/resources The resource files and configuration files that are required to store unit tests3. pom.xml fileEach MAVEN project has a Pom profile, which is also the core configuration file in the MAVEN project. In this file you can configure some information about the current MAVEN project (e.g. dependency configuration, plug-in configuration, project property settings, etc.)4. Basic properties of the configuration item<properties> <!--set the encoding format for the entire MAVEN project-<project.build.sourceencoding>utf-8</ Project.build.sourceencoding> <!--Configure the console output parameter encoding format, solve garbled-and <argline>-dfile.encoding=utf-8</ Argline></properties>maven Configuration PluginMaven itself is made up of a series of plugins, so we can configure some of MAVEN's core plugins through the Pom file.
Add the configuration information for the plugin in the following tab
<build>
<plugins>
Multiple plugins can be configured here
</plugins>
</build>

1. Compiling plugins
<!--Configuring the MAVEN compilation plug-in, specifying the MAVEN compilation version--
<plugin>
<!--compile the plug-in's project name--
<artifactId>maven-compiler-plugin</artifactId>
<!--compile the plug-in configuration information--
<configuration>
<target>1.8</target>
<source>1.8</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

2. Packaging Plugins
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
                <!--  Packaged configuration information  -->
                <configuration>
                   <warsourcedirectory>webcontent</warsourcedirectory>
                   <webxml>webcontent\web-inf\web.xml</webxml>
               </ Configuration>
</PLUGIN>&NBSP;   Dependencies and coordinates 1. Reliance
MAVEN will automatically help us with the class library dependencies required for the project, which is a very powerful place for Maven, and it doesn't require us to manually copy the jar files to the project and then add them to the configuration. Also, MAVEN relies on the process of automatically relying on the needs of other indirectly dependent jars (cyclic dependencies). So we just need some core class libraries, and Maven will do the other dependencies that the class library needs.

2. Coordinates
MAVEN's lookup of dependencies is done based on coordinates. Including the MAVEN project we created ourselves also needs to specify coordinates. Three important attributes of this coordinate are "GAV".
Group Id: This specifies the organization name, which company or organization your project belongs to.
Artifact Id: This specifies the module name (which can also be understood as the project name), because multiple projects can be created under one organization.
Version: The module corresponds to the revision number, a module can have multiple versions, easy to rely on the use of different versions.

Description: When MAVEN is performing dependencies, it is based on this coordinate to find. Organization--modules--version
Find the corresponding jar file so that you can pinpoint a class library that you need to rely on
maven life cycle  maven life cycle
With three complete lifecycles in Maven, all of Maven's managed content can be completed through these lifecycles.
Each set of lifecycles is composed of multiple phases, each of which is a separate command, and each phase of the work is done by a MAVEN plugin. So that's why Maven itself is made up of plugins.

1) Clean life cycle
Pre-clean perform some work that needs to be done before clean
Clean removes all previous build-generated files
Post-clean performs some work that needs to be done immediately after clean
Description: mvn clean command, equivalent to MVN pre-clean clean. As soon as you execute the following command, the previous command executes, and you do not need to re-enter the command.

2) Default life cycle (Focus)
Description: Core parts of the build, compile, test, package, deploy, and so on.
Validate verify that the project is correct and that all necessary information is available
Initialize initializes the build work, such as setting parameters, creating directories, and so on.
Generate-sources generates source code for code that is contained within the compilation scope.
Process-sources processing source code.
Generate-resources generate a resource file.
Process-resources copy and process the resource files to the target directory, ready to package.
Compile the source code of the compiled project.
Process-classes to compile the generated class file for later work, such as Java class bytecode enhancement.
Generate-test-sources generates test source code for the compiled content.
Process-test-sources processing the test source code.
Generate-test-resources the resource files required to generate the test.
Process-test-resources copy and process the resource file to the target test directory.
Test-compile Compile the test source code.
Process-test-classes post-processing work for the class file that compiles the test.
Test runs the tests using the appropriate unit test framework. These test codes are not packaged or deployed.
Prepare-package performs pre-packaging pre-processing work.
The package accepts compiled code, packaged in a ready-to-publish format, such as a JAR.
Pre-integration-test pre-integration testing.
Integration-test deploy the release package to the running test environment on demand.
Post-integration-test perform integration testing.
Verify
Install installs the package to the local repository for other projects to rely on.
Deploy copies the final package to a remote repository for other developers to share with the project.
In Maven, as long as you perform the subsequent stages in the same life cycle, the previous phases are executed, and you do not need to enter the previous phase, which greatly reduces the programmer's work.

3) Site life cycle
Pre-site performs some work that needs to be done before the site documentation is generated
Site-generated Project Web document
Post-site performs some work that needs to be done after the site document is built, and prepares for deployment
Site-deploy Deploy the generated site document to a specific server

MAVEN Installation and Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.