JBoss External Properties Files in Classpath

2019-07-18 12:02发布

问题:

I was going through JBoss.org how to put external file in the classpath, but it doesn't work.

I have 1 file with name "config.properties". It is placed in jboss/modules/com/xsiraul/test/main/ folder. In the same folder there is module.xml which looks like -

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

I have load config.properties file from Java using -

InputStream settingsStream = getClass().getClassLoader().getResourceAsStream("config.properties");  

Java class is in package named com.xsiraul.test

The problem is that method getResourceAsStream returns NULL and I don't understand why. Maybe somebody has any ideas?

I use JBoss EAP 6.1.0.GA version.

回答1:

  1. Copy your 'config.properties' and 'module.xml' in the following directory:

    <JBOSS-6.1-ROOT>/modules/system/layers/base/com/fico/test/main
    
  2. Extend '/standalone/configuration/standalone.xml' by the following sub-system:

    <subsystem xmlns="urn:jboss:domain:ee:1.1">
     <global-modules>
      <module name="com.fico.test" slot="main"/>
     </global-modules>
     <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
     <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
    </subsystem>
    
  3. Restart JBoss



回答2:

Did you declare the dependency to your module? maybe you missed that..

Add Dependencies: com.fico.test to your manifest.mf file



标签: java jboss