JavaWeb maven of the installation configuration and use

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';

Here Insert Picture Description

Configuration environment variable

Open the computer properties ----- ---- ------ environment variables Advanced System Settings -------- ----------- new system variables (set your own installation path)
Here Insert Picture Description
to find the path set to the bin directory of the installation:
Here Insert Picture Description
to test whether the configuration is successful:
open the search box enter: cmd then enter: mvn -version enter to
Here Insert Picture Description
see the success of the set

Modify the configuration file

There are two places you need to configure:

  1. Ali cloud images
  2. Depot_path

First configure Ali cloud images: Configuration is designed to allow faster downloads maven jar package;
Here Insert Picture Description
Here Insert Picture Description
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:
Here Insert Picture Description
Next to configure the default warehouse location:
Here Insert Picture Description
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
Here Insert Picture Description
and then modify the configuration file in the local repository path
Here Insert Picture Description
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?
Here Insert Picture Description
Here Insert Picture Description
For the appropriate folder we set the appropriate file format on it;
Here Insert Picture Description
the question: What target is?

Answer: file output directory, the corresponding out our project file in the folder.
Here Insert Picture Description

idea configure maven

maven address set
for this project:
Here Insert Picture Description
For the default project we can set:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
the project structure test position

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

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/
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
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
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
configuration environment

Output directory, file marks, jdk and so on. . .
Here Insert Picture Description
Check the path Maven
Here Insert Picture Description
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
Here Insert Picture Description
Here Insert Picture Description
that we now import dependence, namely jar package
通过<dependencies></dependencies>标签
Maven project success!
Here Insert Picture Description

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>
Published 84 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/yalu_123456/article/details/97272683