Setting java system properties in jboss

JBoss start up configuration

This short tutorial explains all the things you need to know about the startup process of JBoss AS, how to inject system properties in the application server and how to trace the logs of the start up activities.

How to start JBoss EAP 6 and WildFly

You can start the application server in standalone mode using the following command from $JBOSS_HOME/bin:

Windows users can use the equivalent command:

You can bind the application server public interfaces to a different IP address using:

$ standalone.sh -Djboss.bind.address=192.168.0.1

On the other hand, you can bind the application server management interfaces to a different IP address using:

$ standalone.sh -Djboss.bind.address.management=192.168.0.1

The above commands will start the application server using the default (standalone.xml) configuration file. If you want to use an alternate configuration, you have to include the -c parameter. In the following example, we are starting the application server in standalone mode using the standalone-ha.xml (clustering) configuration:

$ standalone.sh -c standalone-ha.xml

If you want to specify an offset for the server, then you can use the property jboss.socket.binding.port-offset as follows:

$ standalone.sh -Djboss.socket.binding.port-offset=100

In Domain mode, you can start the application server Domain as follows:

Читайте также:  Проверить нажат ли чекбокс javascript

This will pickup the host.xml and domain.xml files from the domain/configuration folder. As an alternative, you can specify a different set of files on the command line:

$ domain.sh -domain-config=mydomain.xml -hostconfig=myhost.xml

Setting System Properties at Startup in WildFly and EAP 6

You have a wide set of options for setting System Properties in the most recent version of the aplication server. You can use the standard -D option, for example:

$ standalone.sh -Dmyproperty=value

You can also use the -P parameter to point to an URL where properties are defined. For example:

$ standalone.sh -P http://somehost/some-location.properties

Finally, Properties can be set via the CLI as in the following example:

[standalone@host:9990 /] /system-property=foo:add(value=bar)

How to start JBoss AS 5 and older versions

Starting the application server is just a matter of launching the start.cmd (Windows) or start.sh (Unix) script.

You can however customize the server startup using several parameters:

The option -b can be used to bind all server services to an IP Address.

run.sh -b 192.168.10.1 # Bind the server on the IP Address 192.168.10.1 run.sh -b 0.0.0.0 # Bind the server on all network interfaces

The option -c can be used to choose which server configuration will be started. If not used the “default” will be chosen.

run.sh -c all # Starts the "all" server configuration

The options -B can be used to add an extra library to the front bootclasspath

This is equivalento to dropping a jar library into $JBOSS_HOME/lib.

The options -L can be used to add an extra library to the loaders classpath

This is equivalent to dropping a jar library into $JBOSS_HOME/common/lib.

You can set a system property through the
-D= option. You can also use the -P option to load the properties from a file.

Create a file named test.properties:

jboss.bind.address=0.0.0.0 jboss.service.binding.set=ports-default

Applications using JGroups library might benefit from the -m and -u option.

-m sets the UDP multicast port; only used by JGroups. -u sets the UDP multicast address

Setting JBoss AS 4/5/6 Server properties using the Properties Service

One cool way to add a list of System properties to JBoss is the Properties MBean Service.
In the deployment folder look for “properties-service.xml”. (if you don’t have it in your release you can create it at any time) :

Now add your properties either in the URLList Attribute or in the Properties Attribute:

   http://somehost/some-location.properties, ./conf/somelocal.properties property1=This is the value of my property property2=This is the value of my other property 

As you can see the The “URLList” is a comma-separated list of URL strings from which to load properties file-formatted content while the “Properties” is a specification of multiple property name=value pairs. Now you can access your properties with standard:

System.getProperty("property1");

Logging the startup process

JBoss uses the Log4jService (in JBoss AS 5.x and earlier) or the LoggingService (in JBoss AS 6.x and later) to configure logging.

However this service is not configured until after the bootstrap phase.

During the bootstrap the microkernel logs into log/boot.log using the configuration defined in log4j.properties (in 5.x and earlier) or logging.properties (in 6.x and later) contained in $JBOSS_HOME/bin/run.jar.

If you want to customize the boot loggin you have basically two options:

  • Change the configuration inside run.jar
  • Use a system property to reference an outside configuration file.

The simplest strategy is to un-jar $JBOSS_HOME/bin/run.jar, change the appropriate properties file and re-jar. (We suggest you using the Open Source archiving software 7-zip which does a good job at editing files inside of archives).

Alternatively, you can also specify the boot log configuration at the command line, instead of editing run.bat/run.sh, for example:

run.bat -Dlog4j.configuration=file:./log4j.properties
run.bat -Dlogging.configuration=file:./logging.properties

Источник

Set System Properties In Jboss

Set System Properties In Jboss explains about how to set the system properties in JBoss Application Server.

In your web application, some times situation arises that you need to set the system properties from JBoss properties file.

In this example, I am going to show how to read the uploaded folder from properties file inside JBoss application server.

JBoss AS 7

If you are using JBoss AS 7, you need to define these properties into following configuration file.

If you are working on Standalone mode, the file is located in the folder [/home/user/jboss-eap-6.2/standalone/configuration/standalone.xml]
If you are working on Domain mode, the file is located in the folder [/home/user/jboss-eap-6.2/domain/configuration/domain.xml]

Below configuration file, I need to set system properties as upload.dir=/home/uploads, here we are specifying key,value pairs. Please check below example configuration

xml version='1.0' encoding='UTF-8'?> server xmlns="urn:jboss:domain:1.5"> extensions> extension module="org.jboss.as.clustering.infinispan"/> extension module="org.jboss.as.connector"/> extension module="org.jboss.as.deployment-scanner"/> extension module="org.jboss.as.ee"/> extension module="org.jboss.as.ejb3"/> extension module="org.jboss.as.jaxrs"/> extension module="org.jboss.as.jdr"/> extension module="org.jboss.as.jmx"/> extension module="org.jboss.as.jpa"/> extension module="org.jboss.as.jsf"/> extension module="org.jboss.as.logging"/> extension module="org.jboss.as.mail"/> extension module="org.jboss.as.naming"/> extension module="org.jboss.as.pojo"/> extension module="org.jboss.as.remoting"/> extension module="org.jboss.as.sar"/> extension module="org.jboss.as.security"/> extension module="org.jboss.as.threads"/> extension module="org.jboss.as.transactions"/> extension module="org.jboss.as.web"/> extension module="org.jboss.as.webservices"/> extension module="org.jboss.as.weld"/> extensions> system-properties> property name="upload.dir" value="/home/uploads"/> system-properties> . . /server> 

JBoss AS 4/JBoss AS 5/JBoss AS 6

If you are using above JBoss versions, you need to add properties into properties-service.xml. It is availabe inside «/deploy/properties-service.xml«. If it is not available, you need create one and add the following details.

server> mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">   | Load properties from each of the given comma seperated URLs --> attribute name="URLList"> /apps/ourapp/ourapp.properties attribute>   | Set raw properties file style properties. --> attribute name="Properties"> upload.dir=/home/uploads attribute> mbean> server> 

How to set System Properties in JBoss

Below example we are going to read the properties file, it is already configured in JBoss Application Server

Required Libraries

Firstly create a Dynamic Web Project (File->New->Dynamic Web Project) named «JBossTutorial» according to following screenshot

Set Properties in JBossSet System Properties In Jboss

Here I am creating a filter and reading the uploaded folder from properties file as we set before. Here we are using JBoss 6.2, so we are adding properties file in standalone.xml

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter ( «/*» )
public class PropertiesFilter implements Filter

@Override
public void destroy ()

@Override
public void doFilter ( ServletRequest request, ServletResponse response,
FilterChain chain ) throws IOException, ServletException PrintWriter out = response.getWriter () ;
out.write ( System.getProperty ( «upload.dir» )) ;
>

@Override
public void init ( FilterConfig fConfig ) throws ServletException

Источник

3.6.11. Configure System Properties Using the Management CLI

The command you use depends on whether you are running a standalone server or a managed domain. If you are running a managed domain, you can add system properties to any or all of the servers running in that domain.

/system-property=PROPERTY_NAME:add(value=PROPERTY_VALUE)
[standalone@localhost:9999 /] /system-property=property.mybean.queue:add(value=java:/queue/MyBeanQueue) "success">
/system-property=PROPERTY_NAME:add(value=PROPERTY_VALUE)
[domain@localhost:9999 /] /system-property=property.mybean.queue:add(value=java:/queue/MyBeanQueue) < "outcome" =>"success", "result" => undefined, "server-groups" =>    < "server-one" =>  "success">>, "server-two" =>  "success">> >>>> >

Add a system property to a host and its server instances in a managed domain using the following syntax:

/host=master/system-property=PROPERTY_NAME:add(value=PROPERTY_VALUE)
[domain@localhost:9999 /] /host=master/system-property=property.mybean.queue:add(value=java:/queue/MyBeanQueue) < "outcome" =>"success", "result" => undefined, "server-groups" =>    < "server-one" =>  "success">>, "server-two" =>  "success">> >>>> >
/host=master/server-config=server-one/system-property=PROPERTY_NAME:add(value=PROPERTY_VALUE)
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=property.mybean.queue:add(value=java:/queue/MyBeanQueue) < "outcome" =>"success", "result" => undefined, "server-groups" =>      "success">>>>>> >
/system-property=PROPERTY_NAME:read-resource
[standalone@localhost:9999 /] /system-property=property.mybean.queue:read-resource < "outcome" =>"success", "result" => "java:/queue/MyBeanQueue"> >
/system-property=PROPERTY_NAME:read-resource
[domain@localhost:9999 /] /system-property=property.mybean.queue:read-resource < "outcome" =>"success", "result" => < "boot-time" =>true, "value" => "java:/queue/MyBeanQueue" > >

Read a system property from a host and its server instances in a managed domain using the following syntax:

/host=master/system-property=PROPERTY_NAME:read-resource
[domain@localhost:9999 /] /host=master/system-property=property.mybean.queue:read-resource < "outcome" =>"success", "result" => < "boot-time" =>true, "value" => "java:/queue/MyBeanQueue" > >
/host=master/server-config=server-one/system-property=PROPERTY_NAME:read-resource
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=property.mybean.queue:read-resource < "outcome" =>"success", "result" => < "boot-time" =>true, "value" => "java:/queue/MyBeanQueue" > >
/system-property=PROPERTY_NAME:remove
[standalone@localhost:9999 /] /system-property=property.mybean.queue:remove "success">
/system-property=PROPERTY_NAME:remove
[domain@localhost:9999 /] /system-property=property.mybean.queue:remove < "outcome" =>"success", "result" => undefined, "server-groups" =>    < "server-one" =>  "success">>, "server-two" =>  "success">> >>>> >

Remove a system property from a host and its server instances in a managed domain using the following syntax:

/host=master/system-property=PROPERTY_NAME:remove
[domain@localhost:9999 /] /host=master/system-property=property.mybean.queue:remove < "outcome" =>"success", "result" => undefined, "server-groups" =>    < "server-one" =>  "success">>, "server-two" =>  "success">> >>>> >
/host=master/server-config=server-one/system-property=PROPERTY_NAME:remove
[domain@localhost:9999 /] /host=master/server-config=server-one/system-property=property.mybean.queue:remove < "outcome" =>"success", "result" => undefined, "server-groups" =>      "success">>>>>> >

Источник

Оцените статью