How to enable property substitution in deployment descriptors in EAP 6/7/8?

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 8.x
    • 7.x
    • 6.x

Issue

  • How to enable property substitution (property replacement) in deployment descriptor in EAP 6 or 7?
  • Can property substitution be used in ejb-jar.xml, for example:
       <enterprise-beans>
          <message-driven>
             <ejb-name>...</ejb-name>
             <ejb-class>...</ejb-class>
             <activation-config>
                ...(snip)...
                <activation-config-property>                    
                   <activation-config-property-name>maxSession</activation-config-property-name>                    
                   <activation-config-property-value>${my.prop.config}</activation-config-property-value>
                </activation-config-property>
                ...(snip)...
             </activation-config>
          </message-driven>
       </enterprise-beans>

and then pass system properties at start-up via command line (e.g, -Dmy.prop.config=20) or via a properties file (e.g. -P myprops.properties) which contains name=value pairs.

  • In web.xml files, system-properties could be defined using ${} form (such as ${property}, set using -Dproperty=xyz and also could be set in the JBoss profile, but the value is not being expanded in the web.xml
 <system-properties>
        <property name="property" value="test"/>
 </system-properties>
  • Is it possible to change the context-root at deploy-time for a web-application in a given EAR file that includes an application.xml file, without changing the EAR file?
  • We are porting application from EAP 5.1.2 to EAP 6.2.0 in testing, observe org.apache.naming.resources.FileDirContext.setDocBase() does not support property substitution in EAP 6. Got the following error:
JBWEB000235: Allocate exception for servlet webdav: java.lang.IllegalArgumentException: JBWEB006706: Document base /opt/testapp/userAA/bin/${userAA.testapp.directory} does not exist or is not a readable directory
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:147)
  • How to use dynamic values in the web.xml file ?
  • How to refer environment variables and/or system properties in web.xml
  • JAVA_OPTS defined variable foo=/somedir. Folder ${foo}/bar exists and got read-write permission for the application. In 6.4, the war file deployed fine. In EAP 7.2, war file deployed failed with error ${foo}/bar does not refer to a valid directory

Resolution

  • As mentioned in the configuration guides for EAP 7 and EAP 6, this behaviour can be enabled using property substitution configuration in the standalone.xml or domain.xml:
        <subsystem xmlns="urn:jboss:domain:ee:1.1">
            <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
            <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
        </subsystem>
  • spec-descriptor-property-replacement ("false" by default) is used to enable or disable property replacement in the following descriptors:

  • To enable the behavior via the Management CLI, run the following command:

/subsystem=ee:write-attribute(name="spec-descriptor-property-replacement",value=true)
  • jboss-descriptor-property-replacement ("true" by default) is used to enable or disable property replacement in the following descriptors:

    • jboss-ejb3.xml
    • jboss-app.xml
    • jboss-web.xml
    • *-jms.xml
    • *-ds.xml
  • To enable the behavior via the Management CLI, run the following command:

/subsystem=ee:write-attribute(name="jboss-descriptor-property-replacement",value=true)

Notes

Property substitution for permissions.xml and jboss-permissions.xml is in EAP 7.4+

Root Cause

  • The spec-descriptor-property-replacement or jboss-descriptor-property-replacement is set to false (depending on the deployment descriptor in which substitution is tried).

  • Certain versions of JBoss EAP 6.x do not have property substitution for the particular deployment descriptor (See bugs mentioned in resolution).

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.