Maven's development tools 03-002 version of IDEA

What is Maven

Project management tools, including a project object model (POM Project Object Model)

Maven can solve any problem

1.jar packet collision
2.Java compiled into a binary file byte code class files
3. prompt code errors, reduce bugs
4. Packing

Maven advantage

Core functions:
1. dependency management , process management is Maven jar package.
Occupy a large memory traditional web project developed CRM projects compiled, jar package in the project.
Maven development of the project jar package is not in the project, but in the jar package repository, quoted by the jar package coordinates. Maven saving disk space to meet the requirements of the code reusable.
2. a key building
projects will be built, test, run, packaging, installation and deployment of a series of processes.
These processes are carried out to Maven, is a key building.
jar package coordinates in the pom.xml
copy Maven Maven project execution path DOS command window open
mvn tomcat: run program run directly up

Maven installation

Configuring maven

Automated build tools
Make "Ant" Maven "Gradle
clean up the
compiled
test
report
package
to deploy
its own configuration maven
Download maven . Unzip to the specified directory, configuration environment variable.
Here Insert Picture Description
Here Insert Picture Description
Note: Win10 system mvn -version command is not an internal command nor the program can be run, you can simply delete brutal MAVEN_HOME, adding bin path (such as D: \ NEW \ apache-maven -3.6.3 \ bin) directly on the Path.
IDEA configuration:
Here Insert Picture Description
After configuring the parameters even broken network can also create project maven
Here Insert Picture Description
settings.xml can be configured: for example warehouses address.
If there is no local repository download will go to the central warehouse, the company can create a remote repository (PW) yourself, you can download via the LAN to the PW.

After modifying pom.xml real-time download, source code and documentation do not automatically download, do not change the basic memory allocation.
Here Insert Picture Description

Maven standard directory structure

Project can be divided into:

  • Part of the core code
  • Profile section
  • Test code section
  • Test the profile
    Maven project standard directory structure
    src / main / java directory: core code part
    src / main / resources directory: Profiles section
    src / test / java directory: test code section
    src / test / resources directory: test configuration file
    src / main / webapp page resources, js, css, images, etc. (if the project is JavaWeb)

Common Commands

mvn clean: 删除target目录
mvn compile:编译
mvn test:测试,test和正式的都会重新编译
mvn package:打包,打出来的包放在target下,pom.xml下package标签指定类型。
mvn install:正式测试都编译,打包后会把包放到本地仓库。
mvn deploy:发布

Maven生命周期

默认生命周期
编译compile》测试test》打包package》安装install》发布deploy
越往后面执行命令时,前面会重新执行一遍。
清理生命周期
清理clean
站点生命周期
实际开发用的不多

双击执行命令,生命周期外的命令可以按图示操作:
Here Insert Picture Description

概念模型图

Here Insert Picture Description
项目对象模型:项目自身信息
项目运行依赖的jar包信息
项目运行环境信息,比如jdk、Tomcat

依赖管理模型

<dependency>
	 <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.2</version>
</dependency>

三个最基本信息公司组织名称,项目名,版本号

默认生命周期:compile,test,package,install,deploy
每个构建项目命令对应Maven底层的一个插件

IDEA集成Maven

前期:已经安装好Maven工具,配置完成。
new project,如果使用骨架可以按图示勾选,然后继续选择下面的,例如quickstart
Here Insert Picture Description
如果main下没有resource文件夹,可以自己创建然后:
Here Insert Picture Description
推荐不使用骨架

Create a web project
Here Insert Picture Description
on the main Java to create a folder, then right mark as source root can be.
IDEA each file folder to place very strict requirements

Resolve conflict jar package

Maven JAR package conflicts troubleshooting and solutions (focus)

plus scope scoped

编译时不起作用
<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
</dependency>
只在测试时起作用
<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
</dependency>

Here Insert Picture Description

maven project to modify the operating environment

Tomcat7 can be run directly by the mvn command: run
Here Insert Picture Description

Learn finishing in Maven Basics (IDEA version)
.

Published 53 original articles · won praise 0 · Views 383

Guess you like

Origin blog.csdn.net/weixin_40778497/article/details/103664973