3 Replies Latest reply on Apr 7, 2014 11:09 AM by littlewing88

    Load arbitrary resources outside ear/war/jar

    littlewing88

      Hi all,

      i would like to load resources from a class without putting them inside my ear/war. The goal for this is to load files which are relative to the environment and the application (application server / war)

      As in this post (http://blog.jyore.com/?p=58), i created a new module and added the dependency to this module inside the MANIFEST of my war.

      The module.xml and the resources are placed in {WILDFLY_HOME}\modules\system\layers\base\com\mycomp\myapp\resources\main

       

      <?xml version="1.0" encoding="UTF-8"?>

      <module xmlns="urn:jboss:module:1.1" name="com.mycomp.myapp.resources">

          <resources>

              <resource-root path="."/>

          </resources>

      </module>

       

      In this folder, as a test, i placed a simle properties file named application_setting.properties.

       

      In a servlet I try to load application_setting.properties

      InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("application_setting.properties");

      but "is" is always null.

       

      Any help is much appreciated!

      Thanks

        • 1. Re: Load arbitrary resources outside ear/war/jar
          jaikiran

          Francesco Calabri wrote:

           

          added the dependency to this module inside the MANIFEST of my war.

          What does it look like? Also post the output of:

           

          jar -tf yourwar.war

           

          Also post the directory listing of {WILDFLY_HOME}\modules\system\layers\base\com\mycomp\myapp\resources\main folder.

          • 2. Re: Re: Load arbitrary resources outside ear/war/jar
            littlewing88

            Thanks for the quick response.

            In my MANIFEST i have the dependency

            Dependencies: com.mycomp.myapp.resources

            The war is deployed exploded inside an ear, so i guess I can't run jar -tf for you, by the way the structure is
            myapp.ear

            `--- META-INF/

            `--- META-INF/MANIFEST.MF (empty)

            `--- META-INF/application.xml

            `--- webapp1.war

            `--- webapp2.war

                 `--- META-INF/
                 `--- META-INF/MANIFEST.MF (the one with the dependency "com.mycomp.myapp.resources")

                 `--- WEB-INF

                 `--- WEB-INF/web.xml

            I don't have any other configuration (such as jboss-deployment-structure.xml) in any other inside the war or the ear.

            In the folder {WILDFLY_HOME}\modules\system\layers\base\com\mycomp\myapp\resources\main i have

            .

            ..

            application_setting.properties

            module.xml


            Thanks!

            • 3. Re: Load arbitrary resources outside ear/war/jar
              littlewing88

              Actually my solution works, maybe I had something wrong elsewhere.
              Thanks