2

最新バージョンの jetty maven プラグインを使用して、異なるポートで複数の Web アプリケーションを実行するにはどうすればよいですか?

org.eclipse.jetty:jetty-maven-plugin9.2.2.v20140723(執筆時のバージョン)。

例えば、

foo.war -> localhost:8080/
bar.war -> localhost:8081/
baz.war -> localhost:8082/

公式ドキュメントでは、これはhttpConnectorの下に記載されています

name: 
   The name of the connector, which is useful for configuring contexts to 
   respond only on particular connectors.

すばらしいので、構成しますnameが、それを にバインドするにはどうすればよいcontextHandlerですか? これは私がこれまでに持っているものです

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.2.2.v20140723</version>
  <configuration>
    <connectors>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>8080</port>
        <name>instance_8080</name>
      </connector>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>8081</port>
        <name>instance_8081</name>
      </connector>
    </connectors>
    <contextHandlers>           
      <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
        <war>a.war</war>
        <contextPath>/</contextPath>
    </contextHandler>
    <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
      <war>b.war</war>
      <contextPath>/</contextPath>
    </contextHandler>
  </contextHandlers> 
</plugin>

このまだ移行されていない wikiconnectorNamesは、 のプロパティを使用して実行できることを示唆していますWebAppContextが、それはもう利用できません。

4

3 に答える 3

4

ドキュメントを見てください:

http://www.eclipse.org/jetty/documentation/current/serving-webapp-from-particular-port.html

コネクタに名前を付けた仮想ホスト メカニズムの拡張機能を使用して、一部の Web アプリケーションを特定のコネクタのみがアクセスできるようにすることもできます。コネクタに setName メソッドを使用して設定された名前「MyConnector」がある場合、これは特別な仮想ホスト名「@MyConnector」で参照できます。

次に、仮想ホストが含まれるため、コンテキストを暗示できます。

http://www.eclipse.org/jetty/documentation/current/configuring-virtual-hosts.html#different-virtual-hosts-different-contexts

@ConnectorName の使用:

@ConnectorName コネクタ名。厳密には仮想ホストではありませんが、代わりに、Connector.setName(String) で設定された一致する名前を持つコネクタで受信した要求のみに一致します。

上記のリンクの構成は、個別の jetty xml 構成ファイルに基づいています。私はこれをテストしていませんが、これを contextHandler (セッターを持つ) に挿入できる可能性があります。

<virtualHosts>
    <virtualHost>@instance_8080</virtualHost>
</virtualHosts>

これは、対応するコネクタにバインドする必要があります。

これは、Java でプログラムによって行うこともできます。

于 2014-09-05T12:55:33.633 に答える
4

@BLuEGoDの回答を拡張すると、完全な作業構成がここにあります

プラグイン構成:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.2.v20140723</version>
    <configuration>
        <jettyXml>path/to/jetty.xml</jettyXml>
    </configuration>
</plugin>

jetty.xml 構成

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Set name="connectors">
    <Array type="org.eclipse.jetty.server.Connector">
        <Item>
            <New class="org.eclipse.jetty.server.ServerConnector">
                <Arg> <Ref refid="Server"/> </Arg>
                <Set name="port">8080</Set>
                <Set name="name">instance_8080</Set>
            </New>
        </Item>
        <Item>
            <New class="org.eclipse.jetty.server.ServerConnector">
                <Arg> <Ref refid="Server"/> </Arg>
                <Set name="port">8081</Set>
                <Set name="name">instance_8081</Set>
            </New>
        </Item>
    </Array>
</Set>

<New id="context-foo" class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="war">foo.war</Set>
    <Set name="virtualHosts">
        <Array type="java.lang.String">
            <Item>@instance_8080</Item>
        </Array>
    </Set>
</New>

<New id="context-bar" class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="war">bar.war</Set>
    <Set name="virtualHosts">
        <Array type="java.lang.String">
            <Item>@instance_8081</Item>
        </Array>
    </Set>
</New>

<Set name="handler">
    <New class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
        <Set name="handlers">
            <Array type="org.eclipse.jetty.server.Handler">
                <Item>
                    <Ref refid="context-foo" />
                </Item>
                <Item>
                    <Ref refid="context-bar" />
                </Item>
                <Item>
                    <New class="org.eclipse.jetty.server.handler.DefaultHandler" />
                </Item>
            </Array>
        </Set>
    </New>
</Set>

于 2014-09-13T19:31:17.500 に答える
0

andの代わりにjettyXmlパラメータを使用して実行しようとします。各戦争のxml 構成ファイルを作成し、pom のパラメーターでそれらを参照します。connectorcontextHandlersjettyXml

于 2014-09-05T11:48:17.427 に答える