此处不允许使用 Maven Jetty 插件守护程序元素

Maven Jetty plugin daemon element not allowed here

我正在尝试配置项目的 pom.xml 文件。我希望它在测试阶段启动 Jetty 服务器。为了做到这一点,我应该像下面那样将 "daemon" 元素添加到 Jetty 插件,但是 IntelliJ 警告我 "Element daemon is not allowed here." 你能帮帮我吗?这是什么原因?

<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的一个bug。它有时无法正确识别某些配置属性。该插件确实有这个 属性,因此除了忽略 IDE 中的错误之外,您别无选择。该插件将按预期工作。

我知道我迟到了四年,但我正在调查同样的问题。

如果将 Jetty 的依赖项更新为 10.0.0,则错误已解决:daemon 不再产生该错误。

但是,如果您更新到 11.0.0(最新,在 Maven Central 上),事情会变得很奇怪:

  • daemon 再次开始产生错误,
  • scanIntervalSeconds 也会产生错误,而以前从未发生过。

所以,我做了一些研究。

我怀疑您从 using jetty and maven-failsafe-plugin 获取了代码。

我读了一些Jetty 11 Programming Guide,发现了这一段:

Here is an example, which turns on scanning for changes every ten seconds, and sets the webapp context path to /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>

此外,我发现 this other paragraph:

Here’s an example of using the pre-integration-test and post-integration-test Maven build phases to trigger the execution and termination of Jetty:

<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>

因此,我将出现的 scanIntervalSeconds 替换为 scan。因此,IntelliJ 不再为第一次出现的错误发出任何信号。然而,第二次出现仍然报错。

daemon而言...

Jetty 9 documentation:

For example, you can configure the plugin to start your webapp at the beginning of your unit tests and stop at the end. To do this, you need to set up a couple of execution scenarios for the Jetty plugin. You use the pre-integration-test and post-integration-test Maven build phases to trigger the execution and termination of 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 上不再工作。
  • 好像也没有必要...