4 Replies Latest reply on Apr 24, 2013 10:49 AM by henk de boer

    Reading EAR/META-INF/application.xml from EJB or WAR module?

    henk de boer Master

      In JBoss AS 6.1 and below I could read the content of an EAR's META-INF or any other directory next to META-INF from a contained EJB or WAR module.

       

      E.g. with a structure as the following:

       

       

      EAR
          META-INF
              application.xml
          conf
              myproperties.xml
          ejbmodule.jar
          warmodule.war
      

       

      I could read both xml files via code such as the following from within e.g. a Singleton EJB, an MBean, etc:

       

      InputStream myProperties = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/myproperties.xml");
      InputStream application = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/application.xml");
      

       

      In JBoss AS/EAP 7/6 this no longer seems to be possible. Both calls return null.

       

      How can I do this now?

        • 1. Re: Reading EAR/META-INF/application.xml from EJB or WAR module?
          Stephen Coy Master

          The fact that this worked in older versions of JBoss was an (un)happy accident.

           

          The content of an EAR file is not available in an application's classpath.

           

          There's a chance that adding something like this jboss-deployment-structure.xml to your EAR/META-INF directory will work, but I have not tested it:

           

          {code:xml}<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">

               <deployment>

                    <resources>

                         <resource-root path="." />

                    </resources>

               </deployment>

          </jboss-deployment-structure>{code}

           

          I'll add that you're probably better off moving your properties file into a module as described in How to put an external file in the classpath.

          • 2. Re: Reading EAR/META-INF/application.xml from EJB or WAR module?
            henk de boer Master

            Hi,

            Stephen Coy wrote:

             

            The fact that this worked in older versions of JBoss was an (un)happy accident.

             

            The content of an EAR file is not available in an application's classpath.

             

            Hmmm, in my (perhaps not so) humble opinion this should then maybe change

             

            There's a chance that adding something like this jboss-deployment-structure.xml to your EAR/META-INF directory will work, but I have not tested it:

             

            Thanks, I'll give it a try.

             

            Meanwhile I found that requesting a resource within the EJB, taking its URL and then working up to the EAR level does seem to work.

             

            E.g.

             

            In packaged mode, I get the following external form of the URL:

             

            vfs:/content/myapp_ear.ear/myapp_business.jar/META-INF/dummy.xml

             

            If I then skip passed the .jar in the path and construct a URL from the following:

             

            vfs:/content/myapp_ear.ear/META-INF/application.xml

             

            Then it thus works. For the exploded deployment the URL is slightly different, but the trick works the same way. What do you think, is this a viable solution?

            • 3. Re: Reading EAR/META-INF/application.xml from EJB or WAR module?
              Stephen Coy Master

              The JEE6 spec is fairly clear when discussing resource/class visibility.

               

              Your solution may get you working for now, but any kind of JBoss upgrade could cause it to stop working because this behaviour is not mandated anywhere.

               

              I'm also curious if it works when you deploy the application via the CLI and/or into a cluster.

              • 4. Re: Reading EAR/META-INF/application.xml from EJB or WAR module?
                henk de boer Master

                Stephen Coy wrote:

                 

                The Java EE 6 spec is fairly clear when discussing resource/class visibility.

                 

                It seems to be indeed, but there's little that can't be changed for say Java EE 8, is there?

                 

                 

                Your solution may get you working for now, but any kind of JBoss upgrade could cause it to stop working because this behaviour is not mandated anywhere.

                 

                I was afraid of that indeed but I guess I'll have to take my chances for now then and see if it's possible to DO get this behavior to be mandated. I never touch the CLI though, and always just copy to the deployment folder, but I'll check it out. Why would a CLI deployment be different? I'll also be sure to check what a cluster deployment does, thanks a lot for the hints!