Configuring JBoss or now WildFly involves setting up different aspects of the server to suit your application and environment needs. These configurations include data sources, security, port settings, logging, JVM options, clustering, and more. Here’s a detailed guide to some of the key configuration areas:
The main configuration files in JBoss/WildFly are located in the standalone/configuration
or domain/configuration
directories.
To configure JVM options like memory limits or garbage collection behavior:
In standalone.conf
, modify the JAVA_OPTS
variable:
JAVA_OPTS="-Xms512m -Xmx2048m -XX:MaxMetaspaceSize=1024m"
By default, JBoss binds to localhost
, which means it only accepts connections from the local machine. To bind JBoss to a public IP (or all available interfaces):
Start the server with the following command:
./standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0
Or modify the standalone.xml
file:
<interfaces>
<interface name="public">
<inet-address value="${jboss.bind.address:0.0.0.0}"/>
</interface>
<interface name="management">
<inet-address value="${jboss.bind.address.management:0.0.0.0}"/>
</interface>
</interfaces>
JBoss/WildFly uses various ports for HTTP, HTTPS, management, and other services. The default port for HTTP is 8080
, and the management console runs on 9990
.
To change the default ports:
standalone.xml
file.<socket-binding-group>
section:<socket-binding-group name="standard-sockets" default-interface="public">
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="management-http" port="9990"/>
<socket-binding name="management-https" port="9993"/>
</socket-binding-group>
Change the port
attributes to the desired values.
To configure a data source for connecting to a database, follow these steps:
standalone/deployments
directory, or you can install it via the admin console under Subsystems > Datasources > JDBC Driver.standalone.xml
file and locate the <datasources>
section:<datasources>
<datasource jndi-name="java:/jdbc/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
</datasources>
Replace the H2 configuration with your database details:
connection-url
: The JDBC URL for your database.driver
: The driver name, which matches the name you set in the JDBC driver configuration.user-name
and password
: Credentials for your database.<datasource jndi-name="java:/jdbc/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>dbuser</user-name>
<password>dbpassword</password>
</security>
</datasource>
Once this is done, you can access the data source in your Java application via JNDI:
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/jdbc/MySQLDS");
Connection conn = ds.getConnection();
To configure HTTPS (SSL) in JBoss/WildFly, you need a keystore containing the SSL certificate.
You can generate a self-signed certificate for testing purposes:
keytool -genkeypair -alias jboss -keyalg RSA -keystore keystore.jks -validity 365 -keysize 2048
This command will create a keystore file named keystore.jks
.
Open standalone.xml
.
Locate the <subsystem xmlns="urn:jboss:domain:web:3.0">
section.
Add an HTTPS listener like this:
<server name="default-server">
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm"/>
</server>
Then, add the keystore to the <security-realms>
section:
<security-realms>
<security-realm name="ApplicationRealm">
<server-identities>
<ssl>
<keystore path="keystore.jks" relative-to="jboss.server.config.dir" keystore-password="password"/>
</ssl>
</server-identities>
</security-realm>
</security-realms>
Make sure the keystore is located in the standalone/configuration
directory or update the path accordingly.
Logging in WildFly is controlled via the <subsystem xmlns="urn:jboss:domain:logging:3.0">
section in standalone.xml
.
You can configure handlers like console
, file
, or periodic-rotating-file-handler
:
<subsystem xmlns="urn:jboss:domain:logging:3.0">
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.myapp">
<level name="DEBUG"/>
<handlers>
<handler name="FILE"/>
</handlers>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
Log Levels: Set appropriate log levels like DEBUG
, INFO
, WARN
, ERROR
.
Log Handlers: Use handlers to define where the logs should be written (console, file, etc.).
If you are running JBoss/WildFly in a cluster, you’ll need to configure clustering for session replication, load balancing, and failover.
standalone-ha.xml
or domain.xml
<subsystem xmlns="urn:jboss:domain:jgroups:3.0">
<stack name="udp">
<transport type="UDP" socket-binding="jgroups-udp"/>
<protocol type="PING"/>
<protocol type="MERGE3"/>
<protocol type="FD_SOCK" socket-binding="jgroups-udp-fd"/>
<protocol type="FD"/>
<protocol type="VERIFY_SUSPECT"/>
<protocol type="pbcast.NAKACK"/>
<protocol type="UNICAST2"/>
<protocol type="pbcast.STABLE"/>
<protocol type="pbcast.GMS"/>
<protocol type="UFC"/>
<protocol type="MFC"/>
<protocol type="FRAG2"/>
</stack>
</subsystem>
Clustering configurations can become more complex depending on your load balancer, session replication method (e.g., sticky sessions), and the number of nodes in your cluster.
Deploying applications in WildFly can be done in several ways:
./jboss-cli.sh --connect --command="deploy /path/to/your/application.war"
standalone/deployments
directory.WildFly provides several tools for monitoring and managing the server:
Regular backups of your WildFly configuration and deployments are essential:
standalone/configuration
or domain/configuration
directories.standalone/deployments
or domain/deployments
directories.Performance tuning involves optimizing various aspects of WildFly:
By carefully configuring JBoss/WildFly, you can optimize it to fit your development or production needs. The primary areas of focus should be JVM tuning, port bindings, security, data source configuration, and logging. Clustering, when necessary, requires additional setup.