Version 7

    This article describes how to include an external properties file in the classpath of an application that has been deployed into versions of JBossAS 7.0 and newer.


    It should be noted that providing application configuration in this way is not a best practice as it does not get automatically propogated to the nodes in a cluster.


    JBoss AS 7.x makes use of the new JBoss Modules framework:

    JBoss Modules is a standalone implementation of a modular (non-hierarchical) class loading and execution environment for Java. In other words, rather than a single class loader which loads all JARs into a flat class path, each library becomes a module which only links against the exact modules it depends on, and nothing more. It implements a thread-safe, fast, and highly concurrent delegating class loader model, coupled to an extensible module resolution system, which combine to form a unique, simple and powerful system for application execution and distribution.

    The secret to getting external files into your application's classpath is to make use of the module classloader.


    1. Create a new module for your configuration files




    Note that from JBossAS 7.2.0.Final and newer (including WildFly 8.x), the module directory structure was changed for JBossAS/WildFly components only. You should continue to use the structure described above. See Layered Distributions and Module Path Organization for more information.


    {code:xml}<?xml version="1.0" encoding="UTF-8"?>

    <module xmlns="urn:jboss:module:1.1" name="com.mycompany.configuration">


            <resource-root path="."/>




    2. Add your properties files to the module












    3. Add your module to your application classpath in a jboss-deployment-structure.xml file

    {code:xml}<?xml version="1.0" encoding="UTF-8"?>




          <module name="com.mycompany.configuration" />





    This file must be placed either in the META-INF directory of your EAR file or the WEB-INF directory of your WAR file. See Class Loading in AS7 for more information.

    4. OR add your module to your application classpath using a MANIFEST.MF entry


    {code}Manifest-Version: 1.0

    Dependencies: com.mycompany.configuration{code}


    5. Load a properties file from the classloader in your application


    {code:java}InputStream settingsStream = this.getClass().getClassLoader().getResourceAsStream("");{code}