【问题标题】:Maven Jetty plugin daemon element not allowed here此处不允许使用 Maven Jetty 插件守护程序元素
【发布时间】:2016-05-01 23:17:41
【问题描述】:

我正在尝试配置项目的 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>

【问题讨论】:

    标签: java maven intellij-idea jetty maven-jetty-plugin


    【解决方案1】:

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

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

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

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

    所以,我做了一些研究。

    我怀疑你是从 using jetty and maven-failsafe-plugin 那里获取代码的。

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

    这里是一个例子,它打开每十次扫描更改 秒,并将 webapp 上下文路径设置为 /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

    这是一个使用预集成测试和 post-integration-test 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 documentation

    例如,您可以配置插件以在 单元测试的开始并在最后停止。为此,您需要 为 Jetty 插件设置几个执行场景。你 使用 pre-integration-test 和 post-integration-test 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 上不再工作。
    • 看来甚至没有必要……

    【讨论】:

      【解决方案2】:

      这实际上是 IntelliJ Idea 的错误。它有时无法正确识别某些配置属性。该插件确实具有此属性,因此除了忽略 IDE 中的错误之外,您别无选择。该插件将按预期工作。

      【讨论】:

      • 是否有关于这个错误的参考,我们可以投票支持?出现不合理的错误真的很烦人,但我不想禁用我的 pom.xml 的架构验证。
      • 凹凸。我也希望看到这个问题得到解决。
      • 您确定daemonrun 目标上的允许配置吗?我只在deploy-war 目标上看到它。 eclipse.org/jetty/documentation/9.4.x/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      相关资源
      最近更新 更多