Maven用eclipse创建web工程

步骤:

第一步:打开Eclipse,点击菜单【File】【New】【Other】

               找到目录Maven,选择Maven Project,点击【Next】

第二步:点击【Next】

第三步:

选择一个Archetype。这里创建Web工程,选择maven-archetype-webapp 版本1.0,点击【Next】

第四步:填写完Group Id和Artifact Id后,点击【Finish】

   将生成一个maven web项目

随后将创建工程。工程结构如下:

解决问题


创建后,报几个问题。

这样解决,打开pom.xml,添加以下东东。

1、添加插件

1 1 <plugin> 2 2 <groupId>org.apache.maven.plugins</groupId> 3 3 <artifactId>maven-war-plugin</artifactId> 4 4 <version>2.6</version> 5 5 <configuration> 6 6 <failOnMissingWebXml>false</failOnMissingWebXml> 7 7 </configuration> 8 8 </plugin> 9 9 <plugin> 1010 <groupId>org.apache.maven.plugins</groupId> 1111 <artifactId>maven-compiler-plugin</artifactId> 1212 <version>3.1</version> 1313 <configuration> 1414 <source>1.8</source> 1515 <target>1.8</target> 1616 </configuration> 1717 </plugin>

2、添加serlvet依赖

1 1 <dependency> 2 2 <groupId>javax.servlet</groupId> 3 3 <artifactId>javax.servlet-api</artifactId> 4 4 <version>3.1.0</version> 5 5 </dependency> 6 6 <dependency> 7 7 <groupId>javax.servlet.jsp</groupId> 8 8 <artifactId>javax.servlet.jsp-api</artifactId> 9 9 <version>2.3.1</version> 1010 </dependency> 1111 <dependency> 1212 <groupId>javax.servlet</groupId> 1313 <artifactId>jstl</artifactId> 1414 <version>1.2</version> 1515 </dependency>

完整的pom.xml

1 1 <project xmlns="http://maven.apache.org/POM/4.0.0" 2 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4 4 <modelVersion>4.0.0</modelVersion> 5 5 <groupId>com.liyongzhen</groupId> 6 6 <artifactId>myweb</artifactId> 7 7 <packaging>war</packaging> 8 8 <version>0.0.1-SNAPSHOT</version> 9 9 <name>myweb Maven Webapp</name> 1010 <url>http://maven.apache.org</url> 1111 <dependencies> 1212 <dependency> 1313 <groupId>javax.servlet</groupId> 1414 <artifactId>javax.servlet-api</artifactId> 1515 <version>3.1.0</version> 1616 </dependency> 1717 <dependency> 1818 <groupId>javax.servlet.jsp</groupId> 1919 <artifactId>javax.servlet.jsp-api</artifactId> 2020 <version>2.3.1</version> 2121 </dependency> 2222 <dependency> 2323 <groupId>javax.servlet</groupId> 2424 <artifactId>jstl</artifactId> 2525 <version>1.2</version> 2626 </dependency> 2727 <dependency> 2828 <groupId>junit</groupId> 2929 <artifactId>junit</artifactId> 3030 <version>3.8.1</version> 3131 <scope>test</scope> 3232 </dependency> 3333 </dependencies> 3434 <build> 3535 <finalName>myweb</finalName> 3636 <plugins> 3737 <plugin> 3838 <groupId>org.apache.maven.plugins</groupId> 3939 <artifactId>maven-war-plugin</artifactId> 4040 <version>2.6</version> 4141 <configuration> 4242 <failOnMissingWebXml>false</failOnMissingWebXml> 4343 </configuration> 4444 </plugin> 4545 <plugin> 4646 <groupId>org.apache.maven.plugins</groupId> 4747 <artifactId>maven-compiler-plugin</artifactId> 4848 <version>3.1</version> 4949 <configuration> 5050 <source>1.8</source> 5151 <target>1.8</target> 5252 </configuration> 5353 </plugin> 5454 </plugins> 5555 </build> 5656 </project>

3、更新这个工程

右击工程名,在弹出的菜单中选择【Maven】【Upadte Project】

点击【OK】

到此项目创建完成,可以运行。

右击工程名,在弹出的菜单中选择【Run As】【Run on Server】

点击【Next】

最后点击【Finish】

运行效果


调整Servlet版本

当前主流Servlet开发或者说主流Java Web开发,Servlet的版本是3.1。(Servlet 4.0还未被大量采用)。

我们在添加依赖时,Servlet版本也是3.1,而maven工程创建时Servlet是2.3

右击工程名,在弹出的菜单中选择【Properties】

弹出对话框,选择【Project Facets】

找到 Dynamice Web Module,去掉前面勾选

将Serlvet版本更改为3.1,再点击【Apply】

再将Dynamice Web Module勾选上去。

最后点击【Apply and Close】

再看,更新过来。


如果有web.xml,可能是这样的

11 <!DOCTYPE web-app PUBLIC 22 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 33 "http://java.sun.com/dtd/web-app_2_3.dtd" > 44 55 <web-app> 66 <display-name>Archetype Created Web Application</display-name> 77 </web-app>

这是Servlet2.3。需要换成Servlet3.1命名空间。

下面是Servlet3.1命名空间。将web.xml改成下面一样的命名空间。

1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 3 xmlns="http://xmlns.jcp.org/xml/ns/javaee" 4 4 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 5 5 id="WebApp_ID" version="3.1"> 6 6 <display-name>myweb</display-name> 7 7 <welcome-file-list> 8 8 <welcome-file>index.jsp</welcome-file> 9 9 </welcome-file-list> 1010 </web-app>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )