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

You need to download

  1. JDK 7
  2. Eclipse 4.2
  3. JBoss 6.2

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

Set Properties in JBoss Set 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

package com.test.filter;


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 {

    }

}

Publishing JBoss Project

Run JBoss

Output

JBoss Output











Your email address will not be published. Required fields are marked *