JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to load external property file in JBoss 7 classpath?


This page talks about how to bring application specific or external property file (any kind of file) into JBoss AS 7.x in the application classpath. Whenever we deploy our application into the application server like JBoss, it is good practice to seperate property files, configuration related files, etc out of deployment bundle. This way we can make sure that any configuration changes does not requires new build. We can edit the configurations in the external files and restart the application. Here are the steps to put external files into the JBoss AS 7.0 and above application classpath:

1) Create a new module for your application configuration files in the JBoss

Create folder structure as shown below and place a file called module.xml inside the last folder.

jboss-as-7-home-folder/modules/com/your-company/configuration/main/module.xml

Update your module.xml file with below shown content:

<?xml version="1.0" encoding="UTF-8"?>  
<module xmlns="urn:jboss:module:1.1" name="com.your-company.configuration">  
    <resources>  
        <resource-root path="."/>  
    </resources>  
</module>  

2) Add all property files under main folder

You have already created folder structure, move all your property files under main folder, these files should be placed along with module.xml file.

3) Create jboss-deployment-structure.xml file in your application and map your module in the xml

Create jboss-deployment-structure.xml file under your application WEB-INF directory of your WAR file. Update your jboss-deployment-structure.xml file with the given below content:

<?xml version="1.0" encoding="UTF-8"?>  
<jboss-deployment-structure>  
  <deployment>  
    <dependencies>  
      <module name="com.your-company.configuration" />  
    </dependencies>  
  </deployment>  
</jboss-deployment-structure>  

4) Load a properties file from the classloader in your application

InputStream is = this.getClass().getClassLoader().getResourceAsStream("MyAppProp.properties");
<< Previous Program | >Next Program >>

JBoss configuration examples

  1. How to start/stop JBoss AS 7 in standalone mode?
  2. How to load external property file in JBoss 7 classpath?
  3. How to configure Data Source (JDBC Connection Pool) in JBoss AS 7 standalone mode?
  4. How to configure database failover and high availability in JBoss 7 Datasource?
Knowledge Centre
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.

wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Famous Quotations
It is easier to fight for one’s principles than to live up to them.
-- Alfred Adler

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.