MyBatis uses Maven in 4-IDEA to create a web project

table of Contents

(1) Open idea, select new a new project, and select the web project template provided by idea with good maven management:

(2) Fill in the maven project information and click Next:

(3) Here are the maven information that we have installed. No changes are made here, click Next:

(4) Click Next and select the directory where the project is located, confirm the project name and project storage path:

(5) Click Finish to start creating the project, and wait patiently until the following interface appears:

(6) Manually add the src/main/java directory, as shown below, right-click the main folder —> New —> Directory:

(7) Create a new folder named java:

(8) After clicking OK, right-click on the new folder java —> Make Directory as —>Sources Root:

(9) The final structure of the javaweb project managed by Maven is as follows:

(10) Open the pom.xml file of the ssm-wind project directly, and add the coordinates of the third-party jar package that you need to rely on:

(11) Configure the local Tomcat server:

(12) Set the project path:

(13) When the project starts, it will automatically pop up:

(14) When adding the coordinates of the jar package, you can also specify the future scope of the jar package:

(15) Set the compiled version of jdk:

(16) Add tomcat in the plug-in without:

(1) Open idea, select new a new project, and select the web project template provided by idea with good maven management:

(2) Fill in the maven project information and click Next:

(3) Here are the maven information that we have installed. No changes are made here, click Next:

(4) Click Next and select the directory where the project is located, confirm the project name and project storage path:

(5) Click Finish to start creating the project, and wait patiently until the following interface appears:

(6) Manually add the src/main/java directory, as shown below, right-click the main folder —> New —> Directory:

(7) Create a new folder named java:

(8) After clicking OK, right-click on the new folder java —> Make Directory as —>Sources Root:

(9) The final structure of the javaweb project managed by Maven is as follows:

(9.1) Initialized pom.xml 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.wind</groupId>
    <artifactId>ssm-wind</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>ssm-wind Maven Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>ssm-wind</finalName>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <!--手动设置jdk编译版本-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

(9.2) Initialized web.xml file:

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>
</web-app>

(10) Open the pom.xml file of the ssm-wind project directly, and add the coordinates of the third-party jar package that you need to rely on:

(11) Configure the local Tomcat server:

(12) Set the project path:

(13) When the project starts, it will automatically pop up:

(14) When adding the coordinates of the jar package, you can also specify the future scope of the jar package:

Each maven project needs to define the coordinates of this project. The coordinates are the identity definition of maven to the jar package. For example, the coordinates of the entry program are defined as follows:

<!--项目名称,定义为组织名+项目名,类似包名-->
<groupId>com.itheima</groupId>

<!-- 模块名称 -->
<artifactId>hello_maven</artifactId>

<!-- 当前项目版本号, snapshot 为快照版本即非正式版本, release 为正式发布版本 -->
<version>0.0.1-SNAPSHOT</version>

<packaging > :打包类型
jar:执行 package 会打成 jar 包
war:执行 package 会打成 war 包
pom :用于 maven 工程的继承,通常父工程设置为 pom

(15) Set the compiled version of jdk:

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
			</configuration>
		</plugin>
    </plugins>
</build>

(16) Add tomcat in the plug-in without:

<build>
	<plugins>
		<plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-compiler-plugin</artifactId>
            <version>2.2</versionversion>
            <configuration>
                <port>8080</port>
                <path>/</path>
			</configuration>
		</plugin>
    </plugins>
</build>

Note: Refer to the blog, thanks: https://www.cnblogs.com/jimlau/p/12157165.html

 

 

 

Guess you like

Origin blog.csdn.net/cmm0401/article/details/111773134