java - 我可以使用 Jetty 部署没有 web.xml 的项目吗?

标签 java spring maven jetty web.xml

我有一个 Spring-Maven 项目,我使用 Java 类配置了该项目,但没有 web.xml。当我使用“mvn jetty:run”部署它时,出现此错误“web.xml 位置不存在 ../src/main/webapp/WEB-INF/web.xml”。

这是我在 pom.xml 中定义的插件。

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.10</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

正如我从 Jetty 文档中读到的那样,我们可以在 jetty:run 目标的配置中定义 web.xml 位置。我们是否也可以对此进行配置,以便 Jetty 使用我的 WebConfig 类作为 web.xml?

最佳答案

您使用的 Jetty 版本不支持 Servlet 3.0 规范,因此 web.xml 是强制性的。使用新的 Jetty 版本来支持 Servlet 3.0(和 xml less 配置)。

切换到eclipse版本的插件

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.0.5.v20130815</version>
</plugin>

更多信息请参见 Jetty/Eclipse documentation .

关于java - 我可以使用 Jetty 部署没有 web.xml 的项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19737236/

相关文章:

Windows 7 和 gnuplot 4.6 下的 Javaplot - 消失的结果

java - 如果我在 Spring Framework 的 @PostConstruct 中初始化对象属性,我应该将它们标记为 volatile 吗?

java - 使用 mule 安装 Maven 错误,jdk 中找不到 com.sun.tools.jar

java - 如何使maven将依赖项的资源文件放入父war而不是依赖项jar中

java - 在 JTable 中的单元格上方显示工具提示

带有 SHAwithECDSA 的 Java Signature.sign() 在多次运行时产生不同的结果

java - 如果按下取消,密码弹出窗口不会关闭程序

java - Spring @ControllerAdvice 不起作用

Spring LocalContainerEntityManagerFactoryBean scanForPackages 和 Hibernate 包级类型定义

maven - 为原型(prototype) :generate on command line 指定原型(prototype)