【问题标题】:Jetty Maven Plugin ignores my jetty.xml for no apparent reasonJetty Maven 插件无缘无故忽略了我的 jetty.xml
【发布时间】:2012-11-18 14:59:04
【问题描述】:

我对这个 Jetty Maven 插件感到有点沮丧..

我正在尝试使用我的 jetty.xml 文件配置 jetty-maven-plugin。 ( 见下文 )。

我希望 Jetty 在端口 8081 上启动。

但是当我运行时,我在控制台中不断收到 8080

mvn jetty:run

我也希望看到日志打印

Configuring Jetty from xml configuration file

我在 jetty-maven-plugin 资源中找到的。但我在任何地方都没有看到它。

我验证了所有文件都在正确的位置,并且到目前为止我尝试了许多不同的配置。

我的 Maven 配置是:

...
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>${jettyVersion}</version>
    <configuration>                       
           <jettyConfig>${project.basedir}/src/main/resources/jetty.xml</jettyConfig>
    </configuration>
</plugin>
.....
<properties>
    <jettyVersion>7.2.0.v20101020</jettyVersion>
</properties>

我的 jetty.xml 文件是:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><SystemProperty name="jetty.host" /></Set>
        <Set name="port"><SystemProperty name="jetty.port" default="8081"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">4</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
  </Arg>
</Call>
</Configure>

我阅读了几乎所有可能的资源,包括 stackoverflow 的所有问答。 我肯定错过了什么。

尽管 Eclipse 在 POM 中将 jetty.xml 的配置参数记录为“jettyXml”,但我还是下载了它们的源代码。它绝对是“jettyConfig”。

查看他们的代码,我看到以下内容

public void applyJettyXml() throws Exception
    {
        if (getJettyXmlFile() == null)
            return;

        getLog().info( "Configuring Jetty from xml configuration file = " + getJettyXmlFile() );        
        XmlConfiguration xmlConfiguration = new XmlConfiguration(getJettyXmlFile().toURL());
        xmlConfiguration.configure(this.server);   
    }

我正在添加 getter 的实现

public File getJettyXmlFile ()
{
    return this.jettyConfig;
}

所以我希望至少能看到打印 Configuring Jetty from xml... - 但它也没有出现..

我设法从命令行覆盖了端口,但我对 XML 配置感兴趣。

【问题讨论】:

    标签: maven-jetty-plugin


    【解决方案1】:

    jettyConfig 重命名为webAppXml

    【讨论】:

      【解决方案2】:

      如果您仍在追求这一点,可以从http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin 尝试两件事。

      1) “您必须通过添加对 jetty-servlets 的依赖来显式启用 Jetty 扩展”

      <plugin>
      ...
          <dependency>
              <groupId>org.eclipse.jetty</groupId>
              <artifactId>jetty-server</artifactId>
              <version>7.2.0.v20101020</version>
          </dependency>
      </plugin>
      

      2) 如果您执行第 1 步,则通过将其(org.mortbay.jetty,而不是 org.eclipse.jetty)放入 settings.xml 来指示 maven 正确的 groupId

      <profile>
            ...
          <pluginGroups>
              <pluginGroup>org.mortbay.jetty</pluginGroup>
          </pluginGroups>
      </profile>
      

      【讨论】:

      • 哇,谢谢。我肯定会很快回到这一点。我目前正在追求别的东西,但是这个问题仍然存在,所以我仍然需要关闭它。
      【解决方案3】:

      您应该尝试将 artifactid 更改为

      &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;

      &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;

      因为你在 jetty.xml 中使用的类都以 org.eclipse.jetty 为前缀,这是在 jetty 7 中引入的

      【讨论】:

        猜你喜欢
        • 2011-06-26
        • 2021-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多