运行多个webapps但端口8080已经在使用中

运行多个webapps但端口8080已经在使用中

本文介绍了tomcat7-maven-plugin:运行多个webapps但端口8080已经在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tomcat7-maven-plugin 来设置嵌入式tomcat容器,在 pre-integration-test中运行webapps 阶段,运行集成测试,然后在 post-integration-test 阶段关闭tomcat。该项目是一个多模块maven项目(包含 app1 app2 等)。父 pom.xml 如下所示,

I'm trying to use tomcat7-maven-plugin to setup an embedded tomcat container, run webapps in pre-integration-test phase, run integration tests, then shutdown tomcat in post-integration-test phase. The project is a multi-module maven project (contains app1, app2, etc). Parent pom.xml looks like following,

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.1</version>
      <configuration>
        <contextFile>path/to/context.xml</contextFile>
        <tomcatUsers>path/to/tomcat-users.xml</tomcatUsers>
        <fork>true</fork>
      </configuration>
      <executions>
        <execution>
          <id>tomcat-run</id>
          <goals>
            <goal>run</goal>
          </goals>
          <phase>pre-integration-test</phase>
        </execution>
        <execution>
          <id>tomcat-shutdown</id>
          <goals>
            <goal>shutdown</goal>
          </goals>
          <phase>post-integration-test</phase>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

然后我只运行 mvn clean integration-test --projects = app1, APP2 当第二个应用开始时,我得到 java.net.BindException

Then I just run mvn clean integration-test --projects=app1,app2. When the second app is starting, I get java.net.BindException,

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"]
java.net.BindException: Address already in use <null>:8080
    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)
    at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1091)
    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:512)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
    at java.net.ServerSocket.bind(ServerSocket.java:328)
    at java.net.ServerSocket.<init>(ServerSocket.java:194)
    at java.net.ServerSocket.<init>(ServerSocket.java:150)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)
    ... 34 more

那么在 tomcat7-maven-plugin 中是否有配置在嵌入式tomcat中运行多个webapp? / p>

So is there a configuration in tomcat7-maven-plugin to run multiple webapps in an embedded tomcat?

推荐答案

参见 mojo参数:您可以配置插件执行以使用其他端口,类似于此配置:

See tomcat7:run mojo parameters: you can configure plugin executions to use other ports, with something similar to this config:

<execution>
    <id>tomcat-run</id>
    <goals>
        <goal>run</goal>
    </goals>
    <phase>pre-integration-test</phase>
    <configuration>
        <port>9090</port>
    </configuration>
</execution>

当然还要为第二个项目使用另一个端口。

And of course use another port for the second project.

这篇关于tomcat7-maven-plugin:运行多个webapps但端口8080已经在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:34