How can I change WildFly listening ports with Mave

2019-07-12 02:44发布

问题:

I'm using wildfly-maven-plugin for my integration tests.

How can I change port default numbers(8080, 8443)?

I couldn't find any configuration property for those port numbers.

UPDATE

I tried yntelectual's answer but ports numbers are still in their default values.

I found this and the port numbers are changed. But the start goal fails yielding "failed to start in XX seconds" may some signaling procedure doesn't know the changed port.

    <executions>
      <execution>
        <id>wildfly-start</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>start</goal>
        </goals>
      </execution>
      <execution>
        <id>wildfly-deploy</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>deploy</goal>
        </goals>
      </execution>
      <execution>
        <id>wildfly-undeploy</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>undeploy</goal>
        </goals>
      </execution>
      <execution>
        <id>wildfly-shutdown</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>shutdown</goal>
        </goals>
      </execution>
    </executions>

Using jvmArgs

<configuration>
  <jvmArgs>-Djboss.socket.binding.port-offset=40000</jvmArgs>
</configuration>

Ports number are still in their default values.

14:25:34,244 INFO  ... Undertow HTTP listener default listening on 127.0.0.1:8080
14:25:35,107 INFO  ... Undertow HTTPS listener https listening on 127.0.0.1:8443
14:25:40,183 INFO  ... Http management interface listening on http://127.0.0.1:9990/management
14:25:40,183 INFO  ... Admin console listening on http://127.0.0.1:9990

Using server-args

<configuration>
  <server-args>
    <server-arg>-Djboss.socket.binding.port-offset=40000</server-arg>
  </server-args>
</configuration>

Port numbers changed but the start goal doesn't finish.

14:29:35,535 INFO  ... Undertow HTTP listener default listening on 127.0.0.1:48080
14:29:36,543 INFO  ... Undertow HTTPS listener https listening on 127.0.0.1:48443
14:29:41,535 INFO  ... Http management interface listening on http://127.0.0.1:49990/management
14:29:41,535 INFO  ... Admin console listening on http://127.0.0.1:49990
BUILD FAILURE
------------------------------------------------------------------------
14:30:07,345 INFO  ... Undertow HTTPS listener https stopped, was bound to 127.0.0.1:48443
14:30:07,347 INFO  ... Undertow HTTP listener default suspending
14:30:07,357 INFO  ... Undertow HTTP listener default stopped, was bound to 127.0.0.1:48080
14:30:07,359 INFO  ... Undertow 1.4.0.Final stopping
14:30:07,365 INFO  ... WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) stopped in 34ms
[INFO] Final Memory: 34M/460M
------------------------------------------------------------------------
Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.2.0.Alpha5:start (wildfly-start) on project ...
The server failed to start: 
The server did not start within 60 seconds. -> [Help 1]

Issues to track

  • https://issues.jboss.org/browse/WFMP-12
  • https://issues.jboss.org/browse/WFMP-14

回答1:

With wildfly maven plugin, you can pass any environment or jvm variable to the server process. JBoss/Wildfly has a notion of port-offset, so that you can add a custom value to all default port number values, e.g. starting the Server with port offset 100, will result in http port listening on 8180. To do that with maven plugin simply specify it as jvm arg:

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <configuration>
        <jvmArgs>-Djboss.socket.binding.port-offset=100</jvmArgs>
    </configuration>
</plugin>

If you want to override any other value, you just need to know its name. Looking at the wildfly config, you will see that the http port for example, is defined in socket binding like so:

<socket-binding name="http" port="${jboss.http.port:8080}"/>

The expression specifies, that if a variable with the name jboss.http.port exists, it will be used as the value. Otherwise the server will fallback to the value specified after colon- :8080. Similarly, https port can be overridden by setting property jboss.https.port. For more info just browse the configuration file(default is standalone.xml) and wildfly plugin docs.



回答2:

You are receiving "failed to start in XX seconds" beacause you have to specify the management port to the maven plug-in:

In your case

<configuration>
  <server-args>
    <server-arg>-Djboss.socket.binding.port-offset=40000</server-arg>
  </server-args>
  <port>49990</port>
</configuration>

Depending on your use case it may be better to set the ports one by one

<configuration>
  <server-args>
    <server-arg>-Djboss.http.port=8080</server-arg>
    <server-arg>-Djboss.https.port=8443</server-arg>
    <server-arg>-Djboss.management.http.port=9991</server-arg>
    <server-arg>-Djboss.management.https.port=9993</server-arg>
  </server-args>
  <port>9991</port>
</configuration>

In this response James R. Perkinsexplains why you need a <port> in your configuration.