工具
- Eclipse 4.6 (Neon)
- jdk 1.8
- maven 3.3.3
创建web项目
maven 命令创建(https://www.cnblogs.com/wkrbky/p/6352188.html)
mvn archetype:create
-DgroupId=com.liwc
-DartifactId=fish
-DarchetypeArtifactId=maven-archetype-webapp
创建好导入IDE
eclipse 创建
-
选择项目类型webapp
image.png -
填写Group Id、artifact Id
image.png -
创建完目录结构
image.png
配置
- 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>com.liwc</groupId>
<artifactId>fish</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>fish Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<!-- 编码utf8 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope><!-- provided表明该包只在编译和测试的时候有效 -->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>fish</finalName>
<plugins>
<!-- jdk1.8编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
-
jdk build path配置 1.8
image.png
更新maven 项目
项目右键--maven--update project
-
部署tomcat
image.png -
启动并打开浏览器访问 http://127.0.0.1:8081/fish/
image.png
-
大功告成
ps 更改Dynamic Web Module 3.0
- web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
</web-app>
- .settings 文件
更改项目.settings文件 org.eclipse.wst.common.project.facet.core.xml
jst.web: 2.3==>3.0
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>
网友评论