创建Maven WAR模块时遇到的两类错误及POM配置
Maven WAR模块构建错误修复方案
错误1:Cannot access default field of properties
- 排查父项目
myssatProject的pom.xml,确保properties节点无语法错误(如属性名非法、格式错误) - 若当前模块包含自定义properties文件,确认文件放置在
src/main/resources目录下,如需资源过滤,添加如下配置到当前pom:
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
- 验证Maven与JDK版本兼容性:Maven 3.8.x及以上推荐搭配JDK 8+
错误2:web.xml is missing and is set to true
两种修复方式任选其一:
- 方式一:添加web.xml
在src/main/webapp/WEB-INF路径下创建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_4_0.xsd" version="4.0"> </web-app>
- 方式二:关闭web.xml检查
若使用Servlet 3.0+规范(无需web.xml),在当前pom.xml中配置maven-war-plugin:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.2</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build>
内容的提问来源于stack exchange,提问作者Tanish Toradmalle
相关产品推荐
相关产品推荐

