【问题标题】:Deploy multiple war in Jetty在 Jetty 中部署多个战争
【发布时间】:2012-05-21 16:19:43
【问题描述】:

我正在使用 jetty maven 插件来部署一些战争。 我有2个模块: moduleA.war 在端口 8180 moduleB.war 在端口 8380

当我使用 maven jetty 插件部署战争时,两个 web 应用程序都试图在端口 8180 上运行,即使我正在为这两个应用程序设置连接器。这是我的 pom 配置:

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.1.3.v20100526</version>
            <configuration>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>8180</port>
                        <name>instance_8180</name>                      
                    </connector>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>8380</port>
                        <name>instance_8380</name>
                    </connector>
                </connectors>                   
                <contextHandlers>
                    <!-- <contextHandler implementation="org.mortbay.jetty.plugin.JettyWebAppContext"> -->
                    <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                        <war>/${project.build.directory}/user-mgmt-web-1.0-SNAPSHOT.war</war> 
                        <contextPath>/user-mgmt-web</contextPath>
                        <connectorNames>
                            <item>instance_8180</item>
                        </connectorNames>
                    </contextHandler>
                    <!-- <contextHandler implementation="org.mortbay.jetty.plugin.JettyWebAppContext"> -->
                    <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                        <war>/${project.build.directory}/services-web-1.0-SNAPSHOT.war</war> 
                        <contextPath>/services-web</contextPath>
                        <connectorNames>
                            <item>instance_8380</item>
                        </connectorNames>
                    </contextHandler>
                </contextHandlers>
                <stopPort>80</stopPort>
                <stopKey>stop</stopKey>
            </configuration>
            <executions>
                <execution>
                    <id>start-container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-container</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

我想知道如何让部署的第二个 webapp 从其分配的端口开始。 当我运行它时,当容器完成初始化第二个 webapp 时,我得到一个地址已在使用中的错误。

阿萨内

【问题讨论】:

  • 感谢您的回复,我是使用堆栈溢出的新手。我会回去接受我之前问题的答案。
  • 如果您查看我的 pom,我正在使用上下文处理程序,并且为每个上下文分配一个带有端口号的连接器。这有意义还是我错过了什么?
  • 有道理。我不以这种方式运行我的项目,我使用单个实例并且只是将其作为建议提供。听起来您打算在多个端口上运行它并且您打算这样做。如果以后这个问题仍然存在,我可能会更深入地研究它,看看我是否能提供帮助。祝你好运!

标签: maven plugins deployment jetty


【解决方案1】:

我认为具有两个不同端口的两个不同模块仅在多个实例中工作,在您的情况下,仅激活第一个端口号为第一个端口设置空闲超时。

<port>8180</port>
<maxIdleTime>"put your time"</maxIdleTime>

然后启动另一个端口。

如果上面不行,试试下面这个

在你的 jetty.xml 添加新的连接器

<!-- original connector on port 8080 -->
<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><Property name="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8080"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">2</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
  </Arg>
</Call>

<!-- new connector on port 8081 --> 
<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><Property name="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8081"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">2</Set>
        <Set name="statsOn">false</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
  </Arg>
</Call>

【讨论】:

  • 感谢您的帮助。我最终覆盖了战争并在同一个端口上运行 webapps。这是完成某事的最快途径。我刚刚调整了我最终要在同一个端口上运行的soapui 项目。我仍然会花一些时间尝试解决如何在时间允许的情况下使用不同的端口在同一个容器中运行战争,似乎我可能不得不编辑 jetty.xml 文件
猜你喜欢
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 2014-08-20
  • 2015-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-13
相关资源
最近更新 更多