maven build SSM framework

First check your environment variables

OS version: windows7
JDK version: JDK 1.8.0_161
maven version: Maven 3.5.3
eclipse version: Oxygen.3a Release (4.7.3a), introduce why you should use the new version of eclipse, because the new version of eclipse has been combined with maven , you can build the maven project directly.

Configure Maven

The download address of maven: http://maven.apache.org/download.cgi
The detailed configuration method will not be introduced one by one here, let's take a look at the version of maven
write picture description here

It is worth noting here that because the maven server is abroad, domestic access may be slower, so here is the mirror node of settings.xml to be replaced and replaced by Alibaba Cloud, which will be much faster when downloading the jar package. .

<mirror>
       <id>nexus-aliyun</id>
       <mirrorOf>*</mirrorOf>
       <name>Nexus aliyun</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
eclipse integrates Maven

Set up eclipse's own maven integration tool, find the Maven node in Preferences, and observe whether the settings of the User Settings item are correct.
write picture description here

There is a point to note here, there are generally two paths for the existence of settings.xml.

  1. Installed place: $M2_HOME/conf/settings.xml
  2. User's directory: ${user.home}/.m2/settings.xml

Then click on the Installations node and add the maven runtime.
write picture description here

Build SSM project with Maven

1. Select Maven Project
write picture description here

2. Click Next and select the default workspace location
write picture description here

3. Select web type
write picture description here

4. Fill in GroupID, ArtifactID
write picture description here

5. Right-click on the project to view the project information. The
default Dynamic Web Module is 2.3. If Tomcat 8.5 is used, it needs to be changed to 3.1.
write picture description here

The modification method is as follows:

1. Find org.eclipse.wst.common.project.facet.core.xml in the directory where the Maven project is located

<installed facet="jst.web" version="2.3"/>

replace with

<installed facet="jst.web" version="3.1"/>

2. Then the web.xml file under the Maven project is modified to

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
       version="3.1" metadata-complete="true">
</web-app>

3. Modify the build node in the pom.xml file and add the following content

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

4. After modification, right-click on the project, find Update Project under Maven properties, click to update the project
5. Click OK to update the maven project, and then observe the project properties, Module has become 3.1

Modify pom.xml and download the jar package required by the SSM framework
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com</groupId>
    <artifactId>SSM</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>ssm Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <!-- Spring版本号 -->
        <spring.version>4.3.8.RELEASE</spring.version>
    </properties>
    <dependencies>
        <!-- Spring相关包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- AOP相关包 -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.0</version>
        </dependency>

        <!-- MyBatis相关包 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.3.0</version>
        </dependency>
        <!-- MySQL相关包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <!-- 数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.20</version>
        </dependency>

        <!-- Spring集成MyBatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.3</version>
        </dependency>

        <!-- JSP标准标签库 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- 日志相关包 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>

        <!-- 单元测试相关包 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>ssm</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Complete project information

write picture description here

Problems you may encounter during configuration

Problem 1:
write picture description here
Solution:
①Set the Server as Tomcat in eclipse ②Right
write picture description here
click on the project, view the project properties, find the Java Build Path, and add the Server Runtime as Tomcat
write picture description here

Question 2:
write picture description here
When I saw this question, the first thing I thought was that maybe because of network problems, when maven downloaded the jar package, the download was not 100% successful, so I went to the .m2 path to check. As shown in the figure:
write picture description here

Indeed because of this issue.
Solution: delete this file. Go back to eclipse, update the whole project, and the whole problem can be solved.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325418433&siteId=291194637