修改maven骨架模板创建web项目中web.xml和pom.xml的模板

Maven创建web项目:

项目场景:使用maven archetype中webapp创建项目
在这里插入图片描述


问题描述

例如:

这样创建出来的web.xml约束头文件老旧,在写多个servlet映射关系时,标签报错,有红色波浪线:

response


在这里插入图片描述

pom.xml文件缺少servlet依赖,需要自己引入,complier编译为1.7

在这里插入图片描述

pom.xml文件里有build报错

在这里插入图片描述



解决方案:更改骨架里提供的模板文件

具体解决方案:
找电脑上的maven本地仓库找org进入找apache进入找maven进入找archetypes进入看到骨架webapp进入找到.jar文件用压缩软件直接打开(不要解压!不要解压!不要解压!
例如:路径 ——>D:\Development\apache-maven-3.6.1\mvn_resp\org\apache\maven\archetypes\maven-archetype-webapp\1.4。
在这里插入图片描述
在这里插入图片描述

用文本软件打开,这里是pom.xml文件,(注意ctrl+S保存不管用,需要关闭文本编辑器保存,会提示)
在这里插入图片描述

这里是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>${groupId}</groupId>
  <artifactId>${artifactId}</artifactId>
  <version>${version}</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>

  </dependencies>


</project>

在这里插入图片描述


同样用文本软件打开,这里是web.xml文件

在这里插入图片描述


这里是web.xml模板,可根据项目需要自行更改

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1"
  metadata-complete="false">//设置使用@WebServlet注解开发  如果为true则注解无效


</web-app>

metadata-complete属性表示部署时当前的配置是否完全,值为true,表示完全,只会应用web.xml的配置,而不会去扫描类似@WebServlet,@WebFilter,@WebListener等注解和web-frame.xml配置。默认值是metadata-complete=false,即不完全,会对项目中类进行扫描,是否有相关的注解配置,同时也会加载web-frame.xml等插件配置。

在这里插入图片描述

  • 6
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值