欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Eclipse用maven构建SSM框架遇到的问题及解决方法

程序员文章站 2024-01-15 21:57:40
...

听说Maven很好用,刚刚好实验了Spring+Mvc企业应用实践的一个小项目,所以就拿它来练手了,用maven来重构它。

开发环境如下:

Eclipse:Eclipse Project Release Notes 4.7 (Oxygen)

JDK:JDK1.8.0_144

Maven:apache-maven-3.5.4

Tomcat:Tomcat 9

环境的配置就不多说了,其实只要有目录就行,Eclipse中配好就可以了

 

首先新建Maven项目,如果是第一次建Maven项目的话,一定要确保网络状态良好,因为任何下载中断或者下载错误都会导致创建Maven项目失败。

Eclipse用maven构建SSM框架遇到的问题及解决方法

这里选webapp

Eclipse用maven构建SSM框架遇到的问题及解决方法

创建完成就报错了,Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:1.0 from any of the configured repositories.可以看出是仓库的问题

Eclipse用maven构建SSM框架遇到的问题及解决方法

原因是archetype错误,去maven仓库删掉它的最后更新文件,重新建就会再下了

 

Eclipse用maven构建SSM框架遇到的问题及解决方法

创建成功,项目目录如下

Eclipse用maven构建SSM框架遇到的问题及解决方法

先把jdk换一下,因为我之前改了maven的settings.xml,所以直接1.8了,不然是1.5

Eclipse用maven构建SSM框架遇到的问题及解决方法

添加的语句如下

Eclipse用maven构建SSM框架遇到的问题及解决方法

<profile>

    <id>jdk-1.8</id>

    <activation>

        <activeByDefault>true</activeByDefault>

        <jdk>1.8</jdk>

    </activation>

    <properties>

        <maven.compiler.source>1.8</maven.compiler.source>

        <maven.compiler.target>1.8</maven.compiler.target>

        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

    </properties>

</profile>

 

再添加tomcat9配置

Eclipse用maven构建SSM框架遇到的问题及解决方法

看一下Project Facet,发现是Module版本是2.3

Eclipse用maven构建SSM框架遇到的问题及解决方法

先不改,直接运行一下,成功了

Eclipse用maven构建SSM框架遇到的问题及解决方法

在网上看了一些资料,说servlet和这个module是有对应版本的,还是把它改高一些把

Eclipse用maven构建SSM框架遇到的问题及解决方法

再打开

Eclipse用maven构建SSM框架遇到的问题及解决方法

Eclipse用maven构建SSM框架遇到的问题及解决方法

Eclipse用maven构建SSM框架遇到的问题及解决方法

再运行,tomcat报了错

Eclipse用maven构建SSM框架遇到的问题及解决方法

再次运行,能成功进去了

接下来先改web.xml,因为改成3.1了,而web.xml里的声明还是2.3,直接删掉就行了

Eclipse用maven构建SSM框架遇到的问题及解决方法

如果你不删会怎么样呢,我被这个错误弄了好久,哈哈Description    Resource    Path    Location    Type
Cannot change version of project facet Dynamic Web Module to 2.3.    fkbookapp-maven        line 1    Maven Java EE Configuration Problem

Eclipse用maven构建SSM框架遇到的问题及解决方法

 

pom.xml添加一些依赖

 

<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>cn.rambo</groupId>
  <artifactId>fkbookapp-maven</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>fkbookapp-maven 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-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-context-support</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-instrument -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-instrument</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-instrument-tomcat -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-instrument-tomcat</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-jms -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-jms</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-messaging</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-jms -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-jms</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-messaging</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-orm</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
		<dependency>
		    <groupId>org.springframework</groupId>
		    <artifactId>spring-oxm</artifactId>
		    <version>4.3.8.RELEASE</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.3.8.RELEASE</version>
    <scope>test</scope>
</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.3.8.RELEASE</version>
</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc-portlet -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc-portlet</artifactId>
    <version>4.3.8.RELEASE</version>
</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-websocket -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
    <version>4.3.8.RELEASE</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>

		<dependency>
		    <groupId>com.mchange</groupId>
		    <artifactId>mchange-commons-java</artifactId>
		    <version>0.2.11</version>
		</dependency>
		
		<dependency>
	    <groupId>com.mchange</groupId>
	    <artifactId>c3p0</artifactId>
	    <version>0.9.5.2</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>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</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>
        
	    <dependency>
	    <groupId>org.apache.ant</groupId>
	    <artifactId>ant</artifactId>
	    <version>1.9.6</version>
		</dependency>
		
		<dependency>
	    <groupId>org.apache.ant</groupId>
	    <artifactId>ant-launcher</artifactId>
	    <version>1.9.6</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
		<dependency>
		    <groupId>org.ow2.asm</groupId>
		    <artifactId>asm</artifactId>
		    <version>5.2</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/cglib/cglib -->
		<dependency>
		    <groupId>cglib</groupId>
		    <artifactId>cglib</artifactId>
		    <version>3.2.5</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
		<dependency>
		    <groupId>org.javassist</groupId>
		    <artifactId>javassist</artifactId>
		    <version>3.22.0-GA</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/ognl/ognl -->
		<dependency>
		    <groupId>ognl</groupId>
		    <artifactId>ognl</artifactId>
		    <version>3.1.16</version>
		</dependency>
		
		
		

    </dependencies>
    
  <build>
    <finalName>fkbookapp-maven</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>

 

Update一下,它会自动下载jar包到仓库

Eclipse用maven构建SSM框架遇到的问题及解决方法

接下来修改建立SSM所需的配置文件,文件内容我上传到github上了https://github.com/Rambo55555/fkbookapp-maven

Eclipse用maven构建SSM框架遇到的问题及解决方法

建立src/main/java目录存java文件

Eclipse用maven构建SSM框架遇到的问题及解决方法

导入项目内容

 

结果:

Eclipse用maven构建SSM框架遇到的问题及解决方法

Eclipse用maven构建SSM框架遇到的问题及解决方法

 

哈哈哈,乌蝇哥

项目地址:https://github.com/Rambo55555/fkbookapp-maven

相关标签: Maven SSM Demo