我得到以下错误:
装配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
是什么导致了这种情况?
当前回答
关于包装,有两件事需要注意。
打包到war文件需要在Catalin Ciolocoiu所描述的适当文件夹中定义web.xml文件。 但是将包类型更改为jar不需要这种结构,并且应该立即工作。
其他回答
如果你能提供你的maven-war-plugin的代码片段,这将是很有帮助的。 看起来web.xml在正确的位置,仍然可以尝试显式地给出位置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
我在测试服务器上有同样的错误,但不是在本地。几分钟后,我发现IDE没有与pom.xml同步。以下是我的解决方法:
使用Eclipse重新生成部署描述符
右键单击项目文件夹 在上下文菜单中,选择“Java EE工具”,然后选择“生成部署描述符存根” 它将创建web.xml文件。
使用IntelliJ重新生成部署描述符
右键单击项目文件夹 在上下文菜单中,选择“打开模块设置”,然后单击+添加web部署描述符。 然后你可以改变你的描述符或Web资源目录的路径。 然后你会得到这样的东西:
发生此错误是因为您告诉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>
我在尝试将Spring Boot项目打包为WAR文件并在独立的Tomcat实例中部署该WAR文件时遇到了这条消息。
我使用Spring initializr来生成初始的pom.xml和相关工件。 问题是在pom.xml (Spring版本2.6.+)中,该依赖项已经就位。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
我不得不把它换成这个:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
并且还添加了范围为"provided"的依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
当然,也改变了包装
<packaging>war</packaging>
我的webXml标签的值需要看起来像这样才能工作:
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>