【问题标题】:webxml attribute is required with Servlet 3.0Servlet 3.0 需要 webxml 属性
【发布时间】:2013-08-13 17:46:57
【问题描述】:

我在尝试编译 Vaadin WAR 时收到此错误:

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project testvaadin-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

我知道这个错误意味着 maven 找不到我的 web.xml,但是在“Vaadin 之书”中它说使用 Servlet API 3.0 和注释 @ 时不需要 web.xml 987654323@ 在您的 UI 类中。

我在一个单独的配置文件中编译我的小部件集(根据this 指南),当我运行这个配置文件时它编译得很好。但是,当我只编译 web 项目时,我得到了上面提到的错误。

什么给了?

我是否会以某种方式覆盖 Maven 行为? Vaadin 甚至没有创建 WEB-INF 目录。我想我可以创建 WEB-INF 文件夹并在其中保留一个“幽灵”web.xml 以保持 maven 快乐,但这似乎不对。

我错过了什么吗?

有人知道解决这个问题的好方法吗?

【问题讨论】:

    标签: maven maven-plugin vaadin vaadin7


    【解决方案1】:

    默认情况下,如果找不到 web.xml,maven-war-plugin 会失败,请参阅here。如果您使用最新的原型创建 Maven 项目,您会将此参数设置为 false:

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
          </plugin>
        </plugins>
      </build>
    

    如果你想使用 web.xml 而不是注解,只需创建 WEB-INF/web.xml 并在其中定义 servlet,详细说明请参阅《Vaadin 之书》。

    【讨论】:

    • 我刚刚找到它。 =) 我实际上在小部件编译中有 failOnMissingWebXml。谢谢
    • 我需要将 2.4 添加到插件中以消除我的所有警告。
    • 请注意,您只需将&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt; 添加到您的&lt;properties&gt; 部分即可更简洁地执行此操作
    • 按照@Sergey Makarov 的建议,刚刚在上面的代码 sn-p 中包含了 web.xml 中的代码 sn-p,它解决了这个问题。非常感谢。在那里节省了 20 分钟。 org.apache.maven.pluginsmaven-war-pluginfalse跨度>
    【解决方案2】:

    可能是您没有遵循此处描述的标准 maven 目录布局Maven directory layout

    【讨论】:

      【解决方案3】:

      我在这里遇到了类似的错误,但使用 Eclise Luna (4.4) 和 Maven 3.0

      我最终这样做了:

      1. WebContent\WEB-INF\web.xml 移动到 src\main\webapp\WEB-INF\web.xml

      2. 使用&lt;webXml&gt;指定web.xml的位置

      <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                        <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins>
            <!-- we dont want the version to be part of the generated war file name -->
            <finalName>${project.artifactId}</finalName>
        </build>
      
      1. 运行 mvn package 并查看 BUILD SUCCESS (for WAR)

      在此之前,我尝试使用 web.xml 文件的原始路径

      <webXml>WebContent\WEB-INF\web.xml</webXml>
      

      但是maven没接,最好按照maven文件夹结构

      http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

      【讨论】:

      • 如果您确实需要在同一个项目的其他部分使用 web.xml,我想这个解决方案可能会非常好。
      【解决方案4】:

      从 3.0.0 版开始,maven-war-plugin 可以直接使用,没有 web.xml

      打包warbinds to a older version of the maven-war-plugin至少到Maven 3.3.9版本,所以你需要在你的pom.xml中明确设置版本:

      <project>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-war-plugin</artifactId>
                      <version>3.0.0</version>
                  </plugin>
              </plugins>
          </build>
      </project>
      

      maven-war-plugin 的早期版本默认将参数failOnMissingWebXml 设置为true,是什么导致了您的问题。如果您需要使用旧版本的插件,请参阅Sergey Makarovs answer,了解如何手动将参数设置为false

      【讨论】:

        猜你喜欢
        • 2011-07-18
        • 2018-05-09
        • 2014-10-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多