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:

?
1
2
3
4
5
6
<?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:

?
1
2
3
4
5
6
7
8
<?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

?
1
InputStream is =  this .getClass().getClassLoader().getResourceAsStream( "MyAppProp.properties" );
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值