对于java+idea+ssm新手来讲,跑一个demo出来简直是灾难呀。。坑!
1、新建maven项目:
一路next直到创建完成项目,maven自动创建项目会输出如下信息:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.249 s
[INFO] Finished at: 2018-09-25T19:35:04+08:00
[INFO] Final Memory: 14M/198M
[INFO] ------------------------------------------------------------------------
[INFO] Maven execution finished
2、此时idea该网页项目已经创建完成,配置tomcat运行试试:点击右上角edit configurations
但是运行的结果是报错:404。这里确实还不确定原因,为什么模板构建出来无法运行。因此做以下修改:
选择删除该Web,新建Web,指定Deployment Descriptors与Web Resource Directory为:
D:\workspace\maventest5\src\main\webapp\WEB-INF\web.xml
D:\workspace\maventest5\src\main\webapp
重新启动tomcat运行得到index.jsp的Hello World!网页。在此基础上进行SSM框架的构建。
3、修改maven配置文件pom.xml自动引入工程所需的jar包,对于oracle的jar包需要特殊处理:
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6-Dversion=11.2.0.1.0 -Dpackaging=jar-Dfile=D:\app\hanbin\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
由于我在maven的conf文件夹下修改了setting.xml文件:
<localRepository>D:\software\maven\apache-maven-3.3.9\repo</localRepository>
导致安装的包默认到对应目录下,而项目对应的reposity文件夹为D:/M2/REPOSITY文件夹内,因此需要将oracle的jar拷到对应的m2文件夹内。
pom.xml如下:
<?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>cn.hb</groupId> <artifactId>ssmdemo5</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>ssmdemo5 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.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <spring.version>5.0.3.RELEASE</spring.version> <mybatis.version>3.4.4</mybatis.version> </properties> <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- 第一部分:Spring 配置--> <!-- Spring core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <!-- Spring DAO --> <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> <!-- Spring mvc --> <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-test</artifactId> <version>${spring.version}</version> </dependency> <!-- 第二部分:Servlet web --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.4</version> </dependency> <!-- 第三部分:数据库和mybatis -->