我得到以下错误:
装配WAR: webxml属性是必需的(如果以更新模式执行,则需要预先存在的WEB-INF/web.xml)
我有web.xml在正确的地方,这是projectname\src\main\webapp\WEB-INF\web.xml
是什么导致了这种情况?
我得到以下错误:
装配WAR: webxml属性是必需的(如果以更新模式执行,则需要预先存在的WEB-INF/web.xml)
我有web.xml在正确的地方,这是projectname\src\main\webapp\WEB-INF\web.xml
是什么导致了这种情况?
当前回答
这是因为您没有在web项目中包含web.xml,并试图使用maven构建war。要解决这个错误,您需要在pom.xml文件中将failOnMissingWebXml设置为false。
例如:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
详情请见博客:https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
其他回答
这是因为您没有在web项目中包含web.xml,并试图使用maven构建war。要解决这个错误,您需要在pom.xml文件中将failOnMissingWebXml设置为false。
例如:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
详情请见博客:https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
你的文件夹结构改变了,所以文件不再在/src/main/webapp/WEB-INF/web.xml ?
为了解决这个问题,我给我的web文件夹命名为webapp,并把它放在src/main中。Maven默认在/src/main/webapp/WEB-INF/web.xml中查找web.xml。如果这样做,则不需要显式地告诉maven web.xml的位置。如果你改变了你的文件夹结构,你的构建最近停止工作,这可能是原因。
注意:这是一个旧的帖子,但是发布的解决方案并没有指出为什么一个正在工作的构建会突然停止工作。
这对我来说也是完美的。
<project>
.....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
发生此错误是因为您告诉Maven将文件打包到war。
<packaging>war</packaging>
你真的需要战争吗?如果没有,把罐子放在那里。 以下是完整的代码:
<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>
<version>1.0-SNAPSHOT</version>
<groupId>com.your.groupid</groupId>
<artifactId>artifactid</artifactId>
<packaging>jar</packaging>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
这个解决方案适合我(我以前使用的是2.2)。此外,我使用基于Java的Servlet 3.0配置,不需要有web.xml文件。