我有一个 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/