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
What is abstract class or abstract method?
We cannot create instance for an abstract class. We can able to create instance for its subclass only. By specifying abstract keyword just before class, we can make a class as abstract class.

public abstract class MyAbstractClass{

}

Abstract class may or may not contains abstract methods. Abstract method is just method signature, it does not containes any implementation. Its subclass must provide implementation for abstract methods. Abstract methods are looks like as given below:

public abstract int getLength();
Famous Quotations
Insanity: doing the same thing over and over again and expecting different results.
-- Albert Einstein

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 © 2017 by Nataraja Gootooru. All Rights Reserved.