可以在Maven payara-micro-maven-plugin 中设置端口以避免"address already in use" 运行 多个实例吗?

Can the port be set in the Maven payara-micro-maven-plugin to avoid "address already in use" running multiple instances?

已从以下位置下载生成的 microprofile/payara 演示应用程序:

https://start.microprofile.io/

启动第一个实例 (demo-service-a) 运行正常。

正在启动单独的实例 (demo-service-b),正在获取...

java.net.BindException: Address already in use: bind
    at java.base/sun.nio.ch.Net.bind0(Native Method)
    at java.base/sun.nio.ch.Net.bind(Net.java:461)
    at java.base/sun.nio.ch.Net.bind(Net.java:453)
    at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
    at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80)
    at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:107)
    at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:64)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:215)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:204)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:53)
    at org.glassfish.grizzly.config.GenericGrizzlyListener.bindTransport(GenericGrizzlyListener.java:211)
    at org.glassfish.grizzly.config.GenericGrizzlyListener.configure(GenericGrizzlyListener.java:339)
    at com.sun.enterprise.v3.services.impl.GrizzlyProxy.initialize(GrizzlyProxy.java:126)
    at com.sun.enterprise.v3.services.impl.GrizzlyService.createNetworkProxy(GrizzlyService.java:664)
    at com.sun.enterprise.v3.services.impl.GrizzlyService.postConstruct(GrizzlyService.java:586)
    at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:303)
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:351)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:463)
    at org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:281)
    at org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:65)
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2102)
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:93)
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:67)
    at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1213)
    at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1144)
    at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$UpOneLevel.run(CurrentTaskFuture.java:762)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
]]

我可以在哪里修改第二个实例的绑定端口 - 以避免上述异常?

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>demo-service-b</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
    <final.name>demo</final.name>
    <payaraVersion>5.194</payaraVersion>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.microprofile</groupId>
      <artifactId>microprofile</artifactId>
      <version>3.2</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>demo</finalName>
  </build>
  <profiles>
    <profile>
      <id>payara-micro</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>fish.payara.maven.plugins</groupId>
            <artifactId>payara-micro-maven-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>bundle</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
                <processId>1234</processId>
              <payaraVersion>${payaraVersion}</payaraVersion>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

我正在使用 Java 11 和 IDE Netbeans 11.1。

payara-micro-maven-plugin 版本:1.0.1

微档案版本:3.2

您可以在 pom.xmlconfiguration 部分配置使用的端口。

要么指定一个端口,本例中为8888:

<commandLineOptions>
    <option>
        <key>--port</key>
        <value>8888</value>
    </option>                       
</commandLineOptions>

或使用自动绑定功能:

<commandLineOptions>
    <option>
        <key>--autobindhttp</key>
        <value>true</value>
    </option>                       
</commandLineOptions>

还有 https (--autobindssl) 的自动绑定选项,用于指定范围 (--autobindrange <number-of-ports>) 或指定 HTTPS 端口 (--sslport <ssl-port-number>)。请参阅此处以供参考:Payara Micro command-line options