Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Definition

Excerpt

The configuration files are the files to add to XML replacements option allows you to modify XML files of your container's configuration . It is internally used by some containers and is accessible for you can to add extra files.using XPath statements.

Info

This feature is only available for standalone local containers (i.e., not for remote containers nor any kind of deployers).

Explanation

In some cases, it is necessary to enrich modify XML files of your container configuration with extra files. This can be done using Cargo's configFiles xmlReplacements option, accessible via the Cargo APIs.

The advantage of using this option is that it can replace configuration properties in your files: simply use, for example, @cargo.servlet.port@ to have it replaced with the port on which the Servlet/JSP container is listening to.

Note
titleCareful with binary files!

If you want to inject binary configuration files (JAR files, for example), you should use setFileProperty (instead of setConfigFileProperty) with the Java API and <files> and <file> (instead of <configfiles> and <configfile>) with the Maven2/Maven3 plugin.

You might for example want to add the advanced login configuration to your JBoss modify the defaultHost for your Tomcat instance.

Example using the Java API

Info

The method's name is setConfigFileProperty rather than addConfigFileProperty; but it actually adds files to the configFiles list.

Code Block
languagejava
LocalContainer container = ...;
StandaloneLocalConfiguration configuration = (StandaloneLocalConfiguration) getLocalContainer().getConfiguration();

FileConfigXmlReplacement loginConfigXmldefaultHost = new FileConfigXmlReplacement();
loginConfigXmldefaultHost.setConfigfilesetFile("src/main/jboss5/login-configconf/server.xml");
loginConfigXmldefaultHost.setToDir("conf");
configuration.setConfigFileProperty(loginConfigXml);

FileConfig sampleRolesProperties = new FileConfig();
sampleRolesProperties.setConfigfile("src/main/jboss5/sample-roles.propertiessetXpathExpression("//Server/Engine");
sampleRolesPropertiesdefaultHost.setToDirsetAttributeName("confdefaultHost");
configurationdefaultHost.setConfigFileProperty(sampleRolesProperties);

FileConfig sampleUsersProperties = new FileConfig();
sampleUsersProperties.setConfigfile("src/main/jboss5/sample-users.propertiessetValue("myhost");
sampleUsersPropertiesconfiguration.setToDiraddXmlReplacement("conf"defaultHost);

Some notes:

  • The attributeName parameter is optional -if you don't specify it, then Cargo will replace directly the value of the node
  • If the value corresponds to an existing configuration

...

  • property (such as cargo.hostname for example) then Cargo will reuse it from the configuration

Example using the ANT tasks

Code Block
languagehtml/xml
<cargo containerId="@{containerId}" action="@{action}">
  <configuration home="${configuration.home}">
    <configfile<xmlreplacement file="${basedir}/src/main/jboss5/login-configconf/server.xml" todirxpathexpression="conf"/>
    <configfile file="${basedir}/src/main/jboss5/sample-roles.properties" todir="conf/props"/>
    <configfile file="${basedir}/src/main/jboss5/sample-users.properties" todir="conf/props"//Server/Engine" attributename="defaultHost" value="myhost"/>
  </configuration>
</cargo>

...

Code Block
languagehtml/xml
<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <container>
      [...]
    </container>
    <configuration>
      <type>standalone</type>
      [...]
      <configfiles><xmlReplacements>
        <configfile><xmlReplacement>
          <file>${project.basedir}/src/main/jboss5/login-config<file>conf/server.xml</file>
          <todir>conf</todir>
        </configfile>
        <configfile>
          <file>${project.basedir}/src/main/jboss5/sample-roles.properties</file><xpathExpression>//Server/Engine</xpathExpression>
          <todir>conf<attributeName>defaultHost</props</todir>attributeName>
        </configfile>
        <configfile>
          <file>${project.basedir}/src/main/jboss5/sample-users.properties</file>  <value>myhost</value>
          <todir>conf/props</todir>
        </configfile>xmlReplacement>
      </configfiles>xmlReplacements>
    </configuration>
  </configuration>
</plugin>