构建WAR软件包时出现Maven错误(缺少web.xml. [英] Maven error while building WAR package (web.xml missing..?)

查看:114
本文介绍了构建WAR软件包时出现Maven错误(缺少web.xml.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行mvn install时,出现以下错误:

While executing mvn install, I'm getting following error:

组装WAR时出错:webxml属性 是必需的(或预先存在的 WEB-INF/web.xml(如果在更新中执行) 模式)

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

我的Web应用程序结构树是这样的:

My web application structure tree is like that:

my-app
|-- pom.xml
|-- src
    |-- ...
    |-- WebContent
        |-- ...
        |-- META-INF
        |-- WEB-INF
            |-- classes
                |-- ...
            |-- lib
            |-- **web.xml**

我的POM文件如下:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>masters.traffic</groupId>
  <artifactId>traffic_web</artifactId>
  <packaging>war</packaging>
  <name>traffic_web</name>
  <version>0.1.0</version>
  <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>                    
                </configuration>
            </plugin>
        </plugins>
  </build>

    ...
</project>

如何正确解决该问题?

How to properly fix that issue ?

致谢

推荐答案

强烈,建议使用

  • 将Java源代码放入src/main/java(并删除sourceDirectory元素)
  • 将Web应用程序源放入src/main/webapp
  • 删除WEB-INF
  • 下的classeslib目录
    • put the Java sources in src/main/java (and remove the sourceDirectory element)
    • put the Web application sources in src/main/webapp
    • remove the classes and lib directories under WEB-INF

    当然,您可以自定义布局,但这是IMO比麻烦多,徒劳的事情.只需遵守约定即可.

    Sure, you can customize the layout but this is IMO more troubles and useless efforts than benefits. Just follow the conventions.

    这篇关于构建WAR软件包时出现Maven错误(缺少web.xml.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆