11 Replies Latest reply on Dec 22, 2016 9:35 AM by nicolas duminil

    How to overload packaged property files with external ones ?

    nicolas duminil Master

      Hello,

      I'm deploying an EAR on Wildfly 10. All my resources are included in the package. For example, the property files are at the root level of the EJB-JAR in the EAR. In order to modify properties, one needs to checkout the project, modify the property files, commit the modifications, rebuild and re-deploy. While it's a good practice to keep all the resources in the deployed archive, sometimes the described process might be heavy, especially for operations, not always aware about Java stuff. So I would need a way to overload the property files in the jar by external ones, that any admin of the host could modify.

       

      So, I created a module.xml file like the following:

       

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

      <module xmlns="urn:jboss:module:1.1" name="...">

        <resources>

          <resource-root path="."/>

        </resources>

      </module>

       

      in the $JBOSS_HOME/modules with the required filesystem hierachy. I have included a jboss-deployment-structure.xml file, having the following content, in my EJB META-INF directory

       

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

      <!DOCTYPE project>

      <jboss-deployment-structure>

        <deployment>

          <dependencies>

            <module name="..." />

          </dependencies>

        </deployment>

      </jboss-deployment-structure>

       

      and after having rebuilded and redeployed, I expected that the propertis loaded by this.getClass().getClassLoader().getResourceAsStream(fileInClasspath) to be the ones defined in the external file in modules rather then the ones defined in the jar.

       

      But no, the same properties defind in the jar are loaded and the other ones defined in modules seem to be ignored.

       

      Is that anything I'm doing wrong ?

       

      Many thanks in advance for any help.

       

      Kind regards,

       

      Nicolas

        • 1. Re: How to overload packaged property files with external ones ?
          Tomaz Cerar Master

          look into using deployment overlays

          • 2. Re: How to overload packaged property files with external ones ?
            nicolas duminil Master

            Not sure what this is supposed to mean ...

            • 4. Re: How to overload packaged property files with external ones ?
              nicolas duminil Master

              Hello, I'm a bit surprized by your communication style and by the way you have to establish conversations. It's like every word costs you money. But thank you anyway. No, I have explained my problem and the way I need to solve it, i.e. using modules. This should work and my point was to report that it doesn't. Then the solution is not to try another way to do it. So, if you have any idea of why it doesn't work, then I would be interested to read you. Otherwise I would be very gratefull to you if you could let other people to reply.

              Many thanks for your help.

              Kind regards,

              Nicolas

              • 5. Re: How to overload packaged property files with external ones ?
                ehugonnet Apprentice

                Well if you wait until WildFly 11 then you'll be able to replace files in your deployment following WFCORE-429: aka explode deployment(s) (still managed) and replace files.

                Deployment overlays (like what ctomc suggested) is another way to do it.

                JBoss Modules are using separated hierarchical classloaders so depending on where you are the resulting hierarchical classpath may not be what you are expecting.

                • 6. Re: How to overload packaged property files with external ones ?
                  nicolas duminil Master

                  Thanks for your time but I don't think that the solution would be neither to wait for Wildfly 11, nore to use jboss-cli which requires the management port opened. As you can imagine, overloading property files doesn't happen in dev or in test, where one may easily build with a different profile such that to take advantage of maven filtering and property management. No, this problem arise more often in production where is difficult to assume that the management port is opened to inbound cli commands.

                   

                  This is why the appropriated solution here is using modules. And this solution works, as explained here .https://blog.jyore.com/2013/05/jboss-eap6as7wildfly-how-to-use-properties-files-outside-your-archive/ This works properly with EAP 6.4 but, for some reasons, doesn't seem to work with Wildfly 10 (it might work with 8 and 9 as confirmed by one of my co-workers). Hence my question: does anyone know why ?

                   

                  Kind regards,

                   

                  Nicolas

                  • 7. Re: How to overload packaged property files with external ones ?
                    jaikiran pai Master

                    nicolas duminil wrote:

                    ....

                    This is why the appropriated solution here is using modules.

                    That isn't the solution for your use case.  As noted by ehugonnet in his reply:

                     

                    JBoss Modules are using separated hierarchical classloaders so depending on where you are the resulting hierarchical classpath may not be what you are expecting.

                     

                    More specifically if the resource (the properties file in your case) is available in the module classloader of your deployment then the module classloader of the dependencies may not be checked for that resource when you use the getResource/getResourceAsStream APIs on the classloader.

                     

                     

                    nicolas duminil wrote:

                     

                    And this solution works, as explained here .https://blog.jyore.com/2013/05/jboss-eap6as7wildfly-how-to-use-properties-files-outside-your-archive/

                    That's not the same thing as your use case. The properties file there only resides in that module and not within the deployment too.

                    • 8. Re: How to overload packaged property files with external ones ?
                      jaikiran pai Master

                      nicolas duminil wrote:

                       

                      Hello,

                      I'm deploying an EAR on Wildfly 10. All my resources are included in the package. For example, the property files are at the root level of the EJB-JAR in the EAR. In order to modify properties, one needs to checkout the project, modify the property files, commit the modifications, rebuild and re-deploy. While it's a good practice to keep all the resources in the deployed archive, sometimes the described process might be heavy, especially for operations, not always aware about Java stuff. So I would need a way to overload the property files in the jar by external ones, that any admin of the host could modify.

                      For a use case like these, I would recommend not to rely (solely) on classloader to get hold of the (properties) resource. Instead, build it in your code itself to have a path to an (optional) properties file external to your packaged application, be passed as some deployment time configuration (via deployment descriptors). In your code you can then check for its presence and use it if present or then fall back to the properties file package within your application (via classloader.getResource() API). That, IMO, should work pretty much on all servers and be portable.

                      • 9. Re: How to overload packaged property files with external ones ?
                        nicolas duminil Master

                        jaikiran pai a écrit:

                         

                        That isn't the solution for your use case. As noted by ehugonnet in his reply:

                        As already mentioned, using jboss-cli in production environment isn't an option.

                         

                        jaikiran pai a écrit:

                         

                        That's not the same thing as your use case. The properties file there only resides in that module and not within the deployment too.

                        The resources/dependencies defined in modules have highest priority over the ones in the deployment archive as follows (from the documentation):

                         

                        1. System Dependencies - These are dependencies that are added to the module automatically by the container, including the Java EE api's.
                        2. User Dependencies - These are dependencies that are added through jboss-deployment-structure.xml or through the Dependencies: manifest entry.
                        3. Local Resource - Class files packaged up inside the deployment itself, e.g. class files from WEB-INF/classes or WEB-INF/lib of a war.
                        4. Inter deployment dependencies - These are dependencies on other deployments in an ear deployment. This can include classes in an ear's lib directory, or classes defined in other ejb jars.

                         

                        Kind regards,

                         

                        Nicolas

                        • 10. Re: How to overload packaged property files with external ones ?
                          nicolas duminil Master

                          jaikiran pai a écrit:

                          For a use case like these, I would recommend not to rely (solely) on classloader to get hold of the (properties) resource. Instead, build it in your code itself to have a path to an (optional) properties file external to your packaged application, be passed as some deployment time configuration (via deployment descriptors). In your code you can then check for its presence and use it if present or then fall back to the properties file package within your application (via classloader.getResource() API). That, IMO, should work pretty much on all servers and be portable.

                          This is poor design. You're relying here on the filesystem but Java EE doesn't know such a thing as the file-system. As a matter of fact, in Java EE you're strictly prohibited from accessing any external resources by any means other than through a "resource manager" (JDBC, JNDI, JCA, etc).

                           

                          Kind regards,

                           

                          Nicolas

                          • 11. Re: How to overload packaged property files with external ones ?
                            nicolas duminil Master

                            I'm updating the case for any further reference. Finally it appears that externalizing properties using modules as explained here .https://blog.jyore.com/2013/05/jboss-eap6as7wildfly-how-to-use-properties-files-outside-your-archive/ works properly. In my case it was just a problem related to a typo.

                            The deployment model is as follows: I have an EAR containing different JARs (EJB-JARs). These JARs have properties files in their META-INF directory. As between these properties some of them are meant to be modified by operations/productions, for example passwords, etc., one should be able to overload these properties. Using modules as explained in the article does that. So, the production engineer creates a new module in the app server home and puts there the required property files. These properties will then overload the ones defined in the JAR itself.

                            Sorry for having reported that this doesn't work, it was a mistake, it works as expected.

                             

                            Kind regards,

                             

                            Nicolas