Eclipse deployment spring MVC + Maven project

Posted by ph0ngwh0ng on Tue, 25 Feb 2020 16:24:30 +0100

Recently, I was tutoring in spring MVC foundation. In view of having contacted Maven before, I couldn't leave it. So Maven was chosen to introduce dependency.

However, my previous work projects have exposed me to SpringBoot+maven, and spring MVC has no maven, both of which I still remember. However, spring MVC + maven, this combination, really hurt me for a few days. All this may be due to my poor foundation.

Next, I'll post the picture to prevent future troubles.

This is my project path, which contains front-end static resources:

Here is my deployment related configuration:

Windows, Preference, Java, Installed JREs, that is to say, the configuration point in the figure below. Although the JRE is configured, the JDK folder is still selected.

Right click the project name, Properties, Java Build Path, Source and Libraries. Please note the configuration:

Here's what I think I didn't pay attention to most: Properties, Deployment Assembly:

Without that Maven dependency, when deployed to Tomcat, the jar package that the project depends on cannot be exported.

My pom file is posted below:

<?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.yuxx.springmvc</groupId>
    <artifactId>spittr</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <!--Use utf-8 Code-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--web-->
        <spring.version>4.3.14.RELEASE</spring.version>
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>${spring.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
        
    </dependencyManagement>
    
    <build>
    	<plugins>
			<plugin>
        		<groupId>org.apache.maven.plugins</groupId>
        		<artifactId>maven-compiler-plugin</artifactId>
        		<configuration>
            		<source>1.8</source>
            		<target>1.8</target>
        		</configuration>
 			</plugin>
 			<plugin>
    			<groupId>org.apache.tomcat.maven</groupId>
    			<artifactId>tomcat7-maven-plugin</artifactId>
    			<version>2.2</version>
    			<configuration>
        			<!-- Be careful tomcat7 Here url -->
        			<url>http://localhost:8080/manager/text</url>
        			<server>tomcat7</server> <!-- The name here must match setting.xml Configured in ID Agreement-->
        			<path>/spittr</path> <!-- The name here is the project name released by the project-->
    			</configuration>
			</plugin>
		</plugins>
    </build>
	
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <!--<scope>test</scope>-->
        </dependency>
        <!--<dependency>-->
        <!--<groupId>log4j</groupId>-->
        <!--<artifactId>log4j</artifactId>-->
        <!--<version>1.2.17</version>-->
        <!--</dependency>-->

        <!--Spring-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>

        <!--<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
        </dependency>-->
        <!--
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
    		<groupId>org.apache.maven.plugins</groupId>
    		<artifactId>maven-compiler-plugin</artifactId>
    		<version>3.7.0</version>
		</dependency>

        <!--system-rules-->
        <dependency>
            <groupId>com.github.stefanbirkner</groupId>
            <artifactId>system-rules</artifactId>
            <version>1.16.0</version>
            <!--<scope>test</scope>-->
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!--Embedded Database-->
        <!--<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
        </dependency>-->

    </dependencies>

</project>

In this way, it can be added to Servers (Tomcat) like a normal web project and started normally.

Topics: Programming Maven Spring Apache Tomcat