Introduction maven
javaWeb, one of the troubles encountered, every time guide jar package, forget it will be very troublesome, as the project becomes large, jar package management changed its trouble, it came into Maven, Maven is not the first project management tools.
The core idea: the agreement is greater than the configuration
Maven will give you ordained how to write java code. It must be in accordance with this specification.
maven installation and configuration
Download and install Maven
And, like Tomcat, Maven also belong to apache;
maven official website: http://maven.apache.org/
After completion of the finished package will be a compression.
We need to extract a place to put the environment on their computers';
Configuration environment variable
Open the computer properties ----- ---- ------ environment variables Advanced System Settings -------- ----------- new system variables (set your own installation path)
to find the path set to the bin directory of the installation:
to test whether the configuration is successful:
open the search box enter: cmd then enter: mvn -version enter to
see the success of the set
Modify the configuration file
There are two places you need to configure:
- Ali cloud images
- Depot_path
First configure Ali cloud images: Configuration is designed to allow faster downloads maven jar package;
configuration xml :
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
These period to the following location:
Next to configure the default warehouse location:
we need to create the position of a local repository, the default is not recommended, because the c drive.
I am here to set up a repository folder in maven installation directory
and then modify the configuration file in the local repository path
up to this point:
Maven completely installed the
question: Why do you want to configure a mirror;
Answer: Because Maven default node in the foreign and domestic walled, download jar package will be relatively slow, there are likely to fail, all of the recommendations to configure a mirror image of the country, it is recommended to use Ali cloud mirror;
IDEA is used maven Notes
Some folders and some not automatically generated, we need to manually create, but then, files manually created folder does not have permission to write java code or storage resources, we need to manually tag. How to configure it?
For the appropriate folder we set the appropriate file format on it;
the question: What target is?
Answer: file output directory, the corresponding out our project file in the folder.
idea configure maven
maven address set
for this project:
For the default project we can set:
the project structure test position
Use Maven Management jar package
Whatever jar package to use, you need to go to the pom.xml configuration;
Jar package dependencies in the following configuration items.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
How to find the location of these jar package where it?
Recommended to the central Maven remote repository Download: Address: https://mvnrepository.com/
essence of analysis:
Maven will correspond to the appropriate mirror site jar package based on the profile;
Jar package by reading the configuration file to the local.
Creating a Maven project manual
Just create an empty folder on behalf of our project, using IDEA open
configuration environment
Output directory, file marks, jdk and so on. . .
Check the path Maven
write pom.xml core file:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.kuang</groupId>
<artifactId>MavenSelf</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
</project>
Then let the idea recognize
that we now import dependence, namely jar package
通过<dependencies></dependencies>标签
Maven project success!
common problem
If your project in IDEA can run successfully, but can not publish running, you can configure resource filtering is not
We need to manually configure the
<!--用来存放一些和项目构建相关的东西-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>