13 Replies Latest reply on Jun 24, 2013 4:10 AM by lwpro2

    Trying to include properties files outside of the WAR?

    johnson_shawn

      I'm very new to JBoss, transistioning from OAS.  On OAS, we have a "applib" folder that sits in our "container", this is where we keep environment specific configuration files - .properties files and such.  I'm trying to figure out the JBoss 7 way to do this.  Most recently (based on a forum post elsewhere)  I put my config files in the root of a jar file - myapp-config.jar, then dropped that jar along with myapp.war into the deployment folder.  I've tried this a few different ways, but none have been successful so far.  My MANIFEST.MF file is basically like this:

       

      Manifest-Version: 1.0
      Class-Path: myapp-config.jar
      

       

       

      This is the error I get when trying to deploy my war.  Any help would be greatly appreciated!

       

      19:57:07,169 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.unit."myapp.war".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."myapp.war".STRUCTURE: Failed to process phase STRUCTURE of deployment "myapp.war"
          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_29]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_29]
          at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_29]
      Caused by: java.lang.IllegalArgumentException: Given parent is not an ancestor of this virtual file
          at org.jboss.vfs.VirtualFile.getPathNameRelativeTo(VirtualFile.java:116) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
          at org.jboss.vfs.VirtualFile.getPathNameRelativeTo(VirtualFile.java:122) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
          at org.jboss.vfs.VirtualFile.getPathNameRelativeTo(VirtualFile.java:122) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
          at org.jboss.vfs.VirtualFile.getPathNameRelativeTo(VirtualFile.java:110) [jboss-vfs-3.1.0.Final.jar:3.1.0.Final]
          at org.jboss.as.server.deployment.module.ManifestClassPathProcessor.createAdditionalModule(ManifestClassPathProcessor.java:193) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
          at org.jboss.as.server.deployment.module.ManifestClassPathProcessor.handlingExistingClassPathEntry(ManifestClassPathProcessor.java:185) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
          at org.jboss.as.server.deployment.module.ManifestClassPathProcessor.deploy(ManifestClassPathProcessor.java:160) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
          ... 5 more
      
        • 1. Re: Trying to include properties files outside of the WAR?
          jmiguel77

          I am having the same problem, have you found any solution ??

          • 2. Re: Trying to include properties files outside of the WAR?
            marcob39

            Looks like as there is no support for environment specific configuration in jboss as7, see https://community.jboss.org/message/645328

            • 3. Re: Trying to include properties files outside of the WAR?
              sfcoy

              Marco Brunelli wrote:

               

              Looks like as there is no support for environment specific configuration in jboss as7, see https://community.jboss.org/message/645328

               

              That is not true at all.

               

              What it is not possible to do is magically add an external file to the classpath so that it can be read as a resource.

               

              However, you can specify environment specific system properties and property files on the command line using the -P option.

               

              We store our environment specific variables in JNDI and just look them up or inject them.

              • 4. Re: Trying to include properties files outside of the WAR?
                marcob39

                Hi Steven, yes you are right and maybe I should have used another wording, as the -P option is providing environment specific configuration, however the SystemPropertiesService in jboss5 solved that in a much better way in my opinion as you did not have to change the cmd line at all.

                • 5. Re: Trying to include properties files outside of the WAR?
                  sfcoy

                  JBoss AS 7.1.x partially supports the SystemPropertiesService functionality, in that individual properties may be added by adding:

                   

                  {code:xml}<system-properties>

                      <property name="p1.myapp" value="..."/>

                      <property name="p2.myapp" value="..."/>

                  </system-properties>{code}

                   

                  to the configuration.

                   

                  This can also be done from the CLI or the web console.

                   

                  I don't believe that the "URLList" form is supported at this time, probably because it makes configuration of a cluster more difficult (which is the case now in JBossAS 6 and earlier). One of the weaknesses of using external property files is ensuring that the actual file (and the correct version of it) is distributed to each node in a cluster.

                  • 6. Re: Trying to include properties files outside of the WAR?
                    johnson_shawn

                    Steven, Do you have any links to examples of HOW you are storing your enviornment specific variables in JNDI?  I'm willing to make the transistion to that, just would like a little more info/example.

                    • 7. Re: Trying to include properties files outside of the WAR?
                      sfcoy

                      Look for the naming subsystem in your standalone.xml and add this to it:

                       

                      {code:xml}<subsystem xmlns="urn:jboss:domain:naming:1.1">

                         <bindings>

                            <simple name="java:jboss/myapp/maxSomethings" type="java.lang.Integer" value="100" />

                         </bindings>

                      </subsystem>{code}

                       

                      Then, in any web, ejb or CDI component you can access it with:

                       

                      {code:java}@Resource(lookup="java:jboss/myapp/maxSomethings")

                      private int maxSomethings;

                      {code}

                       

                      It's almost as easy as this if you're using the Spring Framework as well.

                      • 8. Re: Trying to include properties files outside of the WAR?
                        marcob39

                        Looks cool, however in our deployment process we keep the environment specific properties in dedicated files, jboss as5 provided the capability to register the whole file in the jndi context by configuration. Now I found a way to do this 'manually' with a Bean annotated with @Startup and @Singleton, that reads the properties from a property file and puts them in the jndi context

                         

                        simplified code snippet:

                        ...

                                    String filename="backend-config.properties";

                                    File f = new File(System.getProperty("jboss.server.config.dir"), filename);

                                    Properties p = new Properties();

                                    p.load(new FileInputStream(f));

                                        InitialContext ctx = new InitialContext();

                                        Context propCtx=ctx.createSubcontext("properties/test");

                                        String filenameBase="backend-configuration";

                                        propCtx.rebind(filenameBase, p);

                        • 9. Re: Trying to include properties files outside of the WAR?
                          johnson_shawn

                          Stephen, thanks for your reply.  What I forgot was that we have a 3rd-party library that requires a specifically named file be in the classpath.  We want to avoid deploying this 3rd party library's properties file in our WAR/EAR file as we don't want to create a different WAR/EAR for each environment.  Any other ideas?

                          • 10. Re: Trying to include properties files outside of the WAR?
                            sfcoy

                            I finally got around to figuring out a way to do this and I have documented it in How to put an external file in the classpath.

                            • 11. Re: Trying to include properties files outside of the WAR?
                              librucha

                              Hi.

                              I'm using this construction:

                               

                                private static final String CONFIG_FILE_KEY = "config.file";


                               

                               

                                /**

                                 * Resolve path to global Billing adapter property file.

                                 */

                                public static String tryGetConfigFilePath() {

                                  // try java opts

                                  String configFilePath = System.getProperty(CONFIG_FILE_KEY);

                                  if (!StringUtils.isBlank(configFilePath)) {

                                    return configFilePath;

                                  }

                                  // try environment

                                  configFilePath = System.getenv(CONFIG_FILE_KEY);

                                  if (!StringUtils.isBlank(configFilePath)) {

                                    return configFilePath;

                                  }

                                  throw new IllegalStateException(format("Cannot find configuration of config file. Java property '-D%1$s' or environment property '%1$s' not found. Please set one of it.", CONFIG_FILE_KEY));

                                }

                               

                               

                               

                              in EJB which is annotated as @Startup and @Singleton for binding properties into global config bean. Than I can configure -Dconfig.file=path/to/file or export config.file=path/to/file for define where is property file located.

                              • 12. Re: Trying to include properties files outside of the WAR?
                                softmahi

                                Hi,

                                 

                                We got this by configuring all properties as a module. Consider all properties are under module named 'property'.

                                 

                                1] In  jboss-deployment-structure.xml add dependency of that property module.

                                 

                                <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> 

                                          <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

                                          <deployment>   

                                     <dependencies>   

                                                       <module name="property" slot="main"/>

                                        </dependencies>

                                </deployment>

                                </jboss-deployment-structure>

                                 

                                2]@ /jboss-as-7.1.1.Final/modules  place config module

                                3] Define module.xml (attached)

                                 

                                <module xmlns="urn:jboss:module:1.1" name="property" slot="main">

                                    <properties>

                                        <property name="jboss.api" value="private"/>

                                    </properties>

                                 

                                 

                                    <dependencies>

                                        <!-- No dependencies -->

                                    </dependencies>

                                     <resources>

                                        <resource-root path="."/>

                                    </resources>

                                </module>

                                4] And place all properties under modules/property/main/.

                                 

                                One more approch is configure property as a system property (key value pair)

                                • 13. Re: Trying to include properties files outside of the WAR?
                                  lwpro2

                                  I find in some cases, you might need both:

                                  1. load the properties into system,
                                  2. have the properties in the classpath

                                   

                                  to achieve first, yes, -P or --properties=<path to properties> would work. It would load the properties configuration into system environment.

                                   

                                  in some other cases, you might still want to put the properties in classpath., for example, if you use  spring PropertyPlaceholderConfigurer and specifiy the properties as "classpath:composerinterfacesmgr.properties".  To achive this, you need to create a module for this specific application, and within your application package, the jboss-deployment-structure.xml, load this module.