我正在尝试配置项目的pom.xml文件。我希望它在测试阶段启动 Jetty 服务器。为了做到这一点,我应该像下面所做的那样将"守护进程"元素添加到 Jetty 插件中,但 IntelliJ 警告我"这里不允许使用元素守护进程"。你能帮帮我吗?原因是什么?
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<httpConnector>
<port>8083</port>
</httpConnector>
</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>
</plugins>
</build>
这实际上是 IntelliJ idea 的错误。它有时无法正确识别某些配置属性。该插件确实具有此属性,因此除了忽略 IDE 中的错误之外,您实际上别无选择。该插件将按预期工作。
我迟到了四年,但我正在调查同样的问题。
如果将 Jetty 的依赖项更新为 10.0.0,则会解决错误:daemon
不再产生该错误。
但是,如果您更新到 11.0.0(最新,在 Maven Central 上),事情会变得很奇怪:
-
daemon
再次开始产生错误, -
scanIntervalSeconds
也会产生错误,而以前从未产生过错误。
所以,我做了一些研究。
我怀疑你从使用码头和maven-failsafe-plugin中获取了你的代码。
我阅读了一些 Jetty 11 编程指南,发现了这一段:
下面是一个示例,它每十次打开扫描一次更改秒,并将 Web 应用上下文路径设置为/test:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>{VERSION}</version>
<configuration>
<scan>10</scan>
<webApp>
<contextPath>/test</contextPath>
</webApp>
</configuration>
</plugin>
另外,我发现了另一段:
下面是使用预集成测试和的示例集成后测试 Maven 构建阶段以触发执行和码头终止:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>{VERSION}</version>
<configuration>
<scan>10</scan>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<scan>0</scan>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
因此,我用 scan
替换了scanIntervalSeconds
。因此,IntelliJ 不再发出第一次出现的任何错误的信号。但是,第二次出现仍会产生错误。
就daemon
而言...
在旧的 Jetty 9 文档中:
例如,您可以将插件配置为在单元测试的开始,并在结束时停止。为此,您需要为 Jetty 插件设置几个执行场景。你使用集成前测试和集成后测试 Maven 构建触发Jetty执行和终止的阶段:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>{VERSION}</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>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
这里甚至没有提到daemon
。因此,Failsafe的文档可能存在错误,并且实际上不需要daemon
。
总结:
- 我不知道为什么
daemon
在 10 上工作,而在 11 中不再工作。 - 似乎甚至没有必要...