Please enable Javascript to view the contents

eclipse 使用maven 创建web3.1项目

 ·  ☕ 2 分钟

最近刚刚开始学java, 在框架搭建的过程中, 遭遇了诸多的坑, 和各种各样的不解与困惑, 由于没有什么java的相关基础, 看到各种xml的配置文件, 当真是一个头两个大.

并且并不知道那个配置到底在哪一步需要添加, 具体的东西, 网上教程一堆, 目前最流行的就是SSM框架, 但是所有人都是给出了一堆文案, 你照着网上堆, 没有问题, 一般也可以弄得出来, 但是, 弄完了还是糊里糊涂的, 不知道那句话是干什么的,

鉴于此, 针对于像我这种, 刚开始学java并且有心知道哪些配置文件都是干什么的. (至少是表面上知道, 至于实现原理, 我不懂),

在此将会有3篇小的日记, 记录从搭建一个最简单的maven的web3.1项目  --» 扩展到spring mvc --» 添加mybatis 支持 完成SSM的最基本的框架搭建

高手勿喷, 如果你在看着几篇文章的时候, 有什么看不懂的, 觉得语言描述不够清晰的, 可以随时联系我的qq    280755402

需要创建web3.1 环境需求

tomcat 8.0  – 一定要是8.0+的tomcat 否则不能启动

jdk 8.0

maven 3.3.9

eclipse中配置maven 配置tomcat 配置jdk  不多赘述

然后下一步, 选择maven-archetype-webapp

 完成

pom.xml文件修改

重点是servlet api

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- servlet api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
</dependencies>

把web.xml文件替换成一下内容

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<web-app 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
id="WebApp_ID" 
version="3.1">
  <display-name>Archetype Created Web Application</display-name>
</web-app>

然后右键项目 properties-->java build path --> libraries

双击 jre system library[j2se-1.5]

 然后左侧选 Java Compiler

Compiler compliance level: 改成1.8

关闭properties 窗口

打开 Navigator视图

在.settings里面

org.eclipse.wst.common.project.facet.core.xml

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="java" version="1.8"/>
  <installed facet="jst.web" version="3.1"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

然后就可以用tomcat启动服务了

分享

Koala An
作者
Koala An
一个大自然的搬运工