Can jboss-web.xml have access to properties?
Asked Answered
T

1

5

I am trying to setup my project to use different virtual-host names depending on the environment.

I know I could create directories with a separate jboss-web.xml file in each directory. But I recently moved this project to maven and wanted to take advantage of the profiles. I already have the databases set up so they can be configured differently by the profile by using filters.

jboss-web.xml:

<jboss-web>
    <context-root>/</context-root>
    <virtual-host>${jbossweb.virtualhost}</virtual-host>
</jboss-web>

The environment specific property file has an entry for:

jbossweb.virtualhost=hostname.domain.com

the pom file build section has this definition

    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/webapp/WEB-INF</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

Just for good measure, the profiles section has this configuration:

  <profile>
    <id>dev</id>
    <properties>
      <env>dev</env>
    </properties>
  </profile>

I'm not even sure if what I'm trying to do is possible. When I try it, Jboss-web.xml has the variable name in the virtual-host location and not the value.

Am I barking up the wrong tree?

Thanks,

Eric

Tsarism answered 22/11, 2011 at 10:30 Comment(1)
It looks like you have all the pieces in place. Another slightly different approach is to include the value of jbossweb.virtualhost in the profile definition.Latoshalatouche
T
11

Actually, I've discovered a way to do this:

The jboss-web.xml looks like this now:

<jboss-web>
    <context-root>${jbossweb.contextroot}</context-root>
    <virtual-host>${jbossweb.virtualhost}</virtual-host>
 </jboss-web>

The property file looks like this:

 jbossweb.virtualhost=hostname
 jbossweb.contextroot=/

Then the pom section looks like this for the maven war plugin configuration:

                <webResources>
                    <resource>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <include>jboss-web.xml</include>
                        <targetPath>/WEB-INF</targetPath>
                    </resource>
                </webResources>

And the filters are defined above the plug ins section, but within the build section as follows:

    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
Tsarism answered 22/11, 2011 at 19:26 Comment(2)
the webResources section is sufficient to enable filtering with maven properties on jboss-web.xml.Nicholle
I know this was answered a couple of years ago, so versions may be different; but I was able to get this to work in a Spring Boot project by removing the context-root element from jboss-web.xml and the build picked up the server.context-path from the application.properties file.Twila

© 2022 - 2024 — McMap. All rights reserved.