接着上一篇讲
一、创建子Maven Project,并继承上一篇的ssm-parent
(1)
(2)
(3)
(4)
二、配置ssm-web的pom.xml
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ssm</groupId>
<artifactId>ssm-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ssm-web</artifactId>
<packaging>pom</packaging>
<!-- 添加tomcat插件 这个装在聚合工程中,ssm -->
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<!-- http://localhost:8080 直接跳转index.jsp -->
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
tomcat-maven插件必须配置,这样我们在eclipse中就可以直接运行web项目,从而在浏览器中进行url地址访问
tomcat-maven插件命令:clean tomcat7:run(这个会在下面讲到)
三、安装ssm-web到本地仓库
四、为ssm-web创建一个Maven Module
(1)
(2)
(3)
五、为ssm-web-test添加一个web.xml
(1)创建ssm-web-test子module后,会发现,在eclipse中有个错误提示
错误提示很明显,缺少web.xml
(2)添加web.xml(可以手动加,也可以自动加,这里选自动)
(3)
(4)此时再回过头来看一下ssm-web的pom文件,我们会发现多了一个modules节点
六、配置ssm-web-test的pom.xml
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ssm</groupId>
<artifactId>ssm-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ssm-web-test</artifactId>
<packaging>war</packaging>
<!-- 添加依赖 -->
<dependencies>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- Mybatis 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- FastDFS 客户端工具 jar包 -->
<dependency>
<groupId>fastdfs_client</groupId>
<artifactId>fastdfs_client</artifactId>
<version>1.25</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.conf</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- 一定要把配置文件都关联上 -->
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.conf</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
从pom文件中的依赖jar包我们可以看出来,项目中用到的技术有:
Mybatis(spring-mybatis整合)、Spring(含MVC)、jsp标签、Mybatis分页插件、json解析、mysql连接、数据库连接池(用的是阿里巴巴的原创),文件上传组件(文件上传和下载servlet会用到),JUnit单元测试、FastDFS客户端连接工具包.........
Ctrl+S后,看到ssm-web-test依赖的jar包如下(已经从本地Maven仓库中关联过来了):
其中关于FastDFS的客户端jar包的依赖,需要先手动地在本地仓库中进行配置,具体可以参考我的博文,地址如下:
Java--上传图片至FastDFS的storage server存储器
七、查看ssm-web-test的web.xml配置文件
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>ssm-web-test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
ssm-web-test的入口首页,包含以上几种,我们取其中的一种,在src/main/webapp/下面创建一个jsp页面
内容如下(注意,编码方式,默认的不是UTF-8,需要自行配置,修改默认编码方式为UTF-8)
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ssm-web-test</title>
</head>
<body>
<p>欢迎来到Appleyk的CSDN博客!</p>
</body>
</html>
至此,我们整个web 项目的基础结构图已经搭建完成(后续会在这个结构基础上逐渐完善)
八、运行ssm-web-test,浏览器访问首页index.jsp
(1)
(2)
(3)
(4)浏览器:localhost:8080
为什么不指定index.jsp,我们也可以访问到首页内容呢?
因为我们在ssm-web的pom.xml文件中配置了tomcat-maven插件
至此,入职任务技能单(Maven子工程ssm-web创建结束)!
下一篇:Java Web后端--入职技能任务单(SSM框架搭建)三