1

我对这个 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 配置感兴趣。

4

3 回答 3

1

重命名jettyConfigwebAppXml.

于 2016-03-14T21:45:36.660 回答
0

您应该尝试将 artifactid 从

<artifactId>maven-jetty-plugin</artifactId>

<artifactId>jetty-maven-plugin</artifactId>

因为您在 jetty.xml 中使用的类以 org.eclipse.jetty 为前缀,由 jetty 7 引入

于 2014-01-02T18:22:34.357 回答
0

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

1)“您必须通过添加对 jetty-servlet 的依赖来显式启用 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>
于 2013-03-17T19:41:45.210 回答