maven打包javaweb应用时找不到web.xml
项目结构是这样的
pom.xml里打包配置如下:
<build>
<finalName>pkgs</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
使用maven build时打包失败,报错找不到web.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.637 s
[INFO] Finished at: 2018-10-22T14:29:55+08:00
[INFO] Final Memory: 31M/287M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project Pkgs: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
使用网上搜到的解决方式也不奏效————分别在configuration标签里加:
<!-- 指定web.xml的路径 -->
<webXml>WebContent\WEB-INF\web.xml</webXml>
<!-- 指定jsp、js、css的路劲 -->
<warSourceDirectory>WebContent</warSourceDirectory>
或者:
<webResources>
<resource>
<directory>WebContent</directory>
</resource>
</webResources>
或者:
<!-- 设置WebContent目录为Web目录 -->
<webappDirectory>WebContent</webappDirectory>
<warSourceDirectory>WebContent</warSourceDirectory>
或者设置Project Facets,如下:
都报同样的错。
只有把项目的WebContent改为webapp放在src/main/下,打包才成功
求教啊!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
web.xml的作用
方案一:用web.xml引导
方案二:用内嵌web容器
添加内嵌tomcat插件和升级maven-war-plugin;
maven-war-plugin是跟着servlet规范走的!