10 Replies Latest reply on Nov 20, 2008 3:17 PM by dbschofield

    user defined system properties for JBoss configurations

    dbschofield

      I would like to be able to reference my own Java system properties in the JBoss configuration files, similar to ${jboss.bind.address} used in the bindings.xml.

      I know I can use -Dname=value on the JAVA_OPTS but I would like to avoid the monsterous commandline this would create.

      I looked at the properties service but this does not get initialized at startup so the properties loaded are not available when files like the bindings.xml and profile.xml get loaded.

      I am hoping the bootstrap process would have a way to do this. Or maybe a standard Java commandline option that loads properties from a file on startup that I am not familiar with.

      Any ideas?

        • 1. Re: user defined system properties for JBoss configurations
          alesj

           

          "dbschofield" wrote:
          Any ideas?

          You can always add another bean to binding.xml.

          e.g.
          <deployment xmlns="urn:jboss:bean-deployer:2.0">
          
           <classloader><inject bean="bindings-classloader:0.0.0"/></classloader>
          
           <classloader name="bindings-classloader" xmlns="urn:jboss:classloader:1.0" export-all="NON_EMPTY" import-all="true">
           <root>${jboss.common.lib.url}jboss-bindingservice.jar</root>
           <root>${jboss.common.lib.url}my-custom-properties-reader.jar</root>
           </classloader>
          
           <bean name="MyCustomPropertiesReader" class="com.acme.PropReader">
           <property name="file">\home\foo\myprops.properties</property>
          


          Note: see that classloader root addition --> my-custom-properties-reader.jar

          • 2. Re: user defined system properties for JBoss configurations
            dbschofield

            That could potentially work but I need the properties available for all configuration files. So the question is now where is the proper place in the JBoss startup process to add a bean which will load the properties before any configuration files are loaded?

            • 3. Re: user defined system properties for JBoss configurations
              alesj

               

              "dbschofield" wrote:
              So the question is now where is the proper place in the JBoss startup process to add a bean which will load the properties before any configuration files are loaded?

              See bootstrap.xml.
              That's the order how boot files are deployed, vfs.xml being the first.
              You can either update that one or squeeze your own in, as the first one.

              • 4. Re: user defined system properties for JBoss configurations
                alesj

                 

                "alesj" wrote:

                vfs.xml being the first.

                In CR2 there is no such file yet.
                It was only added 2 weeks ago (in trunk) - under initialize.xml.
                It was today renamed to vfs.xml.

                Complicated. :-)


                • 5. Re: user defined system properties for JBoss configurations
                  dbschofield

                  I appreciate your help on this. A new boot file at the beginning of bootstrap.xml looks like it will work perfect for what I need.

                  For my own knowledge I am curious to know where JBoss sets its standard system properties such as ${jboss.server.name} and ${jboss.lib.url}?

                  I have to admit I have not searched the source code yet.

                  • 6. Re: user defined system properties for JBoss configurations
                    alesj

                     

                    "dbschofield" wrote:

                    For my own knowledge I am curious to know where JBoss sets its standard system properties such as ${jboss.server.name} and ${jboss.lib.url}?

                    ServerConfigImpl

                    • 7. Re: user defined system properties for JBoss configurations
                      dbschofield

                      I have been trying to create my own bootstrap configuration by referencing my-properties.xml at the beginning of the bootstrap.xml

                      <bootstrap xmlns="urn:jboss:bootstrap:1.0">
                       <url>my-properties.xml</url>
                       <url>classloader.xml</url>
                       <url>aop.xml</url>
                       <url>jmx.xml</url>
                       <url>deployers.xml</url>
                       <url>bindings.xml</url>
                       <url>profile.xml</url>
                      </bootstrap>


                      I am running into problems loading the jar file which has my system properties loader implementation. If I try to create my own classloader I get messages about it not being registered and if I try to use an existing classloader like the bootstrap-classloader it complains that the classloader is already registered. Given my deployment file:

                      <?xml version="1.0" encoding="UTF-8"?>
                      
                      <!--
                       Loads Java properties files into the System.properties for use in JBoss configurations
                      -->
                      <deployment xmlns="urn:jboss:bean-deployer:2.0">
                      
                      <bean name="SystemPropertiesLoader" class="com.foo.SystemPropertiesLoader">
                      <constructor> <parameter>${jboss.server.home.dir}/conf/my.properties</parameter>
                       <parameter class="boolean">true</parameter>
                       </constructor>
                       </bean>
                      </deployment>


                      My question is, how do I need to define my own classloader in the deployment file with classpath "${jboss.home.url}/my_dir/lib/SystemPropertiesLoader.jar" so it plays nice with JBoss?


                      • 8. Re: user defined system properties for JBoss configurations
                        alesj

                         

                        "dbschofield" wrote:

                        My question is, how do I need to define my own classloader in the deployment file with classpath "${jboss.home.url}/my_dir/lib/SystemPropertiesLoader.jar" so it plays nice with JBoss?

                        I don't think you can, until the classloading.xml is initialized.
                        But since you want to have your props handling before that,
                        I guess you will have to put your jar into JBOSS_HOME/lib.

                        Then add this to your bean:
                        <bean name="SystemPropertiesLoader" class="com.foo.SystemPropertiesLoader">
                        <classloader><null/></classloader>
                        <constructor> <parameter>${jboss.server.home.dir}/conf/my.properties</parameter>
                         <parameter class="boolean">true</parameter>
                         </constructor>
                         </bean>
                        

                        Note: classloader element ;-)

                        • 9. Re: user defined system properties for JBoss configurations
                          dimitris

                          have you also tried:

                          run -P path-to-properties-file

                          • 10. Re: user defined system properties for JBoss configurations
                            dbschofield

                            Thanks dimitris, I knew there was a silver bullet out there somewhere. Works like a champ.

                            To Ales's credit I have learned a lot about the bootstrap process in JBoss 5 :)