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
Can we call servlet destory() from service()?
As you know, destory() is part of servlet life cycle methods, it is used to kill the servlet instance. Servlet Engine is used to call destory(). In case, if you call destory method from service(), it just execute the code written in the destory(), but it wont kill the servlet instance. destroy() will be called before killing the servlet instance by servlet engine.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

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] or you can comment on the page.

Most Visited Pages

Other Interesting Sites

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