Servlet 3.0需要webxml属性

时间:2022-02-03 17:16:04

I get this error when trying to compile a Vaadin WAR:

尝试编译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]

I know this error means that maven cannot find my web.xml, but in the "Book of Vaadin" it says that web.xml is not needed when using Servlet API 3.0 and the Annotation @WebServlet in your UI class.

我知道这个错误意味着maven无法找到我的web.xml,但在“Book of Vaadin”中它表示在UI类中使用Servlet API 3.0和Annotation @WebServlet时不需要web.xml。

I am compiling my widgetsets in a separate profile (according to this guide) and it compiles fine when I rnu this profile. However, when I compile only the web-project, I get above mentioned error.

我正在一个单独的配置文件中编译我的widgetset(根据本指南),当我输入此配置文件时,它编译得很好。但是,当我只编译web项目时,我得到上面提到的错误。

What gives?

是什么赋予了?

Do I override the maven behaviour somehow? Vaadin didn't even create a WEB-INF directory. I guess I could create WEB-INF folder and keep a "ghost" web.xml in there to keep maven happy, but that doesn't seem right.

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

Am I missing something?

我错过了什么吗?

Does anyone know a good solution to this?

有谁知道这个很好的解决方案?

4 个解决方案

#1


105  

By default maven-war-plugin will fail if it can't find web.xml, see here. If you are creating Maven project using latest archetype, you will get this parameter set to false:

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

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

If you want to use web.xml instead of annotations, just create WEB-INF/web.xml and define servlet there, see Book of Vaadin for detailed instruction.

如果要使用web.xml而不是注释,只需创建WEB-INF / web.xml并在那里定义servlet,有关详细说明,请参阅Book of Vaadin。

#2


3  

I landed here with a similar error but using Eclise Luna (4.4) with Maven 3.0

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

I ended up doing this:

我最终这样做了:

  1. move the WebContent\WEB-INF\web.xml to src\main\webapp\WEB-INF\web.xml

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

  2. Use the <webXml> to specify the location of web.xml

    使用 指定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. Run mvn package and see a BUILD SUCCESS (for WAR)
  2. 运行mvn包并查看BUILD SUCCESS(用于WAR)

Before this I tried using the original path of the web.xml file

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

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

But maven did not pickit up and is best to follow the maven folder structure

但maven没有选择,最好遵循maven文件夹结构

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

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

#3


1  

Since version 3.0.0 the maven-war-plugin works out of the box with no web.xml.

从版本3.0.0开始,maven-war-plugin开箱即用,没有web.xml。

Up to at least Maven version 3.3.9 the packaging war binds to a older version of the maven-war-plugin, so you need to explicitly set the version in your pom.xml:

至少至少Maven版本3.3.9,打包战争绑定到旧版本的maven-war-plugin,因此您需要在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>

Earlier versions of the maven-war-plugin had the parameter failOnMissingWebXml set to true by default, what causes your problem. See Sergey Makarovs answer on how to manually set the parameter to false if you need to use a older version of the plugin.

早期版本的maven-war-plugin默认情况下将参数failOnMissingWebXml设置为true,这会导致您的问题。如果您需要使用旧版本的插件,请参阅Sergey Makarovs关于如何手动将参数设置为false的答案。

#4


0  

Could be that you are not following the standard maven directory layout as described here Maven directory layout

可能是你没有遵循Maven目录布局中描述的标准maven目录布局

#1


105  

By default maven-war-plugin will fail if it can't find web.xml, see here. If you are creating Maven project using latest archetype, you will get this parameter set to false:

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

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

If you want to use web.xml instead of annotations, just create WEB-INF/web.xml and define servlet there, see Book of Vaadin for detailed instruction.

如果要使用web.xml而不是注释,只需创建WEB-INF / web.xml并在那里定义servlet,有关详细说明,请参阅Book of Vaadin。

#2


3  

I landed here with a similar error but using Eclise Luna (4.4) with Maven 3.0

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

I ended up doing this:

我最终这样做了:

  1. move the WebContent\WEB-INF\web.xml to src\main\webapp\WEB-INF\web.xml

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

  2. Use the <webXml> to specify the location of web.xml

    使用 指定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. Run mvn package and see a BUILD SUCCESS (for WAR)
  2. 运行mvn包并查看BUILD SUCCESS(用于WAR)

Before this I tried using the original path of the web.xml file

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

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

But maven did not pickit up and is best to follow the maven folder structure

但maven没有选择,最好遵循maven文件夹结构

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

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

#3


1  

Since version 3.0.0 the maven-war-plugin works out of the box with no web.xml.

从版本3.0.0开始,maven-war-plugin开箱即用,没有web.xml。

Up to at least Maven version 3.3.9 the packaging war binds to a older version of the maven-war-plugin, so you need to explicitly set the version in your pom.xml:

至少至少Maven版本3.3.9,打包战争绑定到旧版本的maven-war-plugin,因此您需要在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>

Earlier versions of the maven-war-plugin had the parameter failOnMissingWebXml set to true by default, what causes your problem. See Sergey Makarovs answer on how to manually set the parameter to false if you need to use a older version of the plugin.

早期版本的maven-war-plugin默认情况下将参数failOnMissingWebXml设置为true,这会导致您的问题。如果您需要使用旧版本的插件,请参阅Sergey Makarovs关于如何手动将参数设置为false的答案。

#4


0  

Could be that you are not following the standard maven directory layout as described here Maven directory layout

可能是你没有遵循Maven目录布局中描述的标准maven目录布局