3

Mvaen

content:

  1. Introduction to maven
  2. maven function
  3. maven create
  4. maven package directory structure
  5. How maven creates a web project
  6. How to import xml project management in maven
  7. maven life cycle

One, maven overview

  1. Apache Maven is a software project management and comprehensive tool, based on object model (POM) , Maven can manage project construction, reports and files from a central piece of information.
  2. maven : Essentially a management project software maven is produced by Apche and also written in java.

Second, the role of maven

  1. project life cycle: compile, test, package, deploy and run.
  2. management (jar package): maven can help us manage the jar packages needed for development.
  3. management plug-in: maven can help us manage the plug-ins that we need in a unified way.

Maven creation

1. The first step: Click File in the upper right corner and then new Porject
Then choose maven next

点击maven

2. The second step:

第二步

Groupld: package structure (directory)
Artifactld: project name
Version: version number


Package directory structure

结构

Maven configuration introduction

mian       -> 主工程的代码
java目录   -> 写java代码
test       -> 测试代码
resources  -> 存放配置文件的目录
pom.xml    -> 当前maven工程的配置文件{
    a.jar包依赖
    b.插件管理    
}

How to create a web project

How to configure webapp directory and web.xml

Step 1: Click File --> Project Structure...
Click on Facets to copy this path (look at your own)
3

Step 2: Copy and paste here
4

third step
Click Apply How to click OK


How to import xml project management in maven

If you find pom.xml after the previous configuration is complete

<!-- 项目发出,都要先打包(类似于压缩)
        
    打包方式:
            java项目  —> jar包 ( java archives )
            web项目 —> war包  ( java archives)
            pom文件 —> 
            默认 jar
-->
    
    <groupId>com.kjzz</groupId> <!-- 域名 -->
    <artifactId>maven_text03</artifactId> <!-- 项目名 -->
    <version>1.0-SNAPSHOT</version> <!-- 版本号 -->
    <packaging>war</packaging>  <!-- 打包方式 -->
    


 <dependencies>
    <!-- 测试  -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    <!-- mysql连接工具  -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.32</version>
        </dependency>
    <!-- servlet   -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
     <!-- jsp页面 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>

    
<!--设置插件-->
    <build>
        <plugins>
            <!--JDK编译插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- tomcat7插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <!--
                        解决get请求乱码
                    -->
                    <uriEncoding>utf-8</uriEncoding>
                    <port>8080</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>

maven life (project) cycle

Maven function: create a project

三套声明周期
    1. clean :  清理之前构造生产的文件(重要)
        mvn clean 清除编译生成的文件(target目录)
    
    2. default : 核心 {
    
            1.default 创建     
            
            2.compile 编译  
            
            3.text 测试
            运行所有测试(text)代码
            
            4.package 打包 
            java项目: jar (成功了)
            web项目: war
            
            5.install 安装    
            安装本地maven仓库(坐标)
    }    
   
   注意事项:
   1. 直接执行后续步骤,前置步骤自动执行
   2. 前置步骤失败,后续步骤不再执 
   3. site : 产生报告,发布站点 (展示用不到)

Note: maven and idea are not the same manufacturer, so there is no need to be compatible with idea

Added idea function: click file
show is Explorer is the current directory of the opened file


嘻嘻硕
27 声望12 粉丝

想当一只天然呆的鸭qwq