You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Claus, Janek (NIH/NICHD)" <cl...@mail.nih.gov> on 2005/10/24 20:10:37 UTC

How to use different context.xml files?

All,

One of the possibilities Tomcat 5.5 suggest for the context configuration of a web 
application is a file named "context.xml" in the META-INF of your webapp.

In my case it declares a datasource, which differs depending on the deployment environment.

Question: how can I use different context.xml for different environments? Filters don't 
work, because the file is not part of "resources", but webapp/META-INF (because, when it's 
part of resources it gets packaged under WEB-INF/classes).

I'm trying to figure out the best way to do this, using context.xml or external 
configuration files (which will need to be deployed and undeployed each time the web-app 
get's deployed or undeployed)

Thx for any help!

Janek

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different context.xml files?

Posted by "Claus, Janek (NIH/NICHD)" <cl...@mail.nih.gov>.
Thank you very much, this helped!

I hadn't even looked at profiles. They solve this problem very elegantly.

Janek


Mark Hobson wrote:
> Hi Janek,
> 
> Filtering is obviously the best way to achieve this, but we need to
> resolve MNG-791 first.
> 
> An alternative way which I'm using in the interim is to use profiles.
> You'll need to create multiple versions of your context.xml and
> configure the war plugin accordingly, e.g.:
> 
>   src
>   |_ profiles
>     |_ default
>       |_ webapp
>         |_ META-INF
>           |_ context.xml
>     |_ live
>       |_ webapp
>         |_ META-INF
>           |_ context.xml
>     |_ ...
> 
> Then setup your pom with something like:
> 
>   <project>
>     ...
>     <profiles>
>       <profile>
>         <id>default</id>
>         <activation>
>           <activeByDefault>true</activeByDefault>
>         </activation>
>         <build>
>           <plugins>
>             <plugin>
>               <artifactId>maven-war-plugin</artifactId>
>               <configuration>
>                 
> <warSourceDirectory>profiles/default/webapp</warSourceDirectory>
>               </configuration>
>             </plugin>
>           </plugins>
>         </build>
>       </profile>
>       <profile>
>         <id>live</id>
>         <build>
>           <plugins>
>             <plugin>
>               <artifactId>maven-war-plugin</artifactId>
>               <configuration>
>                 
> <warSourceDirectory>profiles/live/webapp</warSourceDirectory>
>               </configuration>
>             </plugin>
>           </plugins>
>         </build>
>       </profile>
>       ...
>     </profiles>
>     ...
>   </project>
> 
> Then just use "mvn -P<profile> war" to build your war with the given
> profile's context.xml, e.g. "mvn -Plive war" for the 'live' profile,
> or just use the default with a "mvn war"
> 
> Mark
> 
> On 24/10/05, Claus, Janek (NIH/NICHD) <cl...@mail.nih.gov> wrote:
>  > All,
>  >
>  > One of the possibilities Tomcat 5.5 suggest for the context 
> configuration of a web
>  > application is a file named "context.xml" in the META-INF of your 
> webapp.
>  >
>  > In my case it declares a datasource, which differs depending on the 
> deployment environment.
>  >
>  > Question: how can I use different context.xml for different 
> environments? Filters don't
>  > work, because the file is not part of "resources", but 
> webapp/META-INF (because, when it's
>  > part of resources it gets packaged under WEB-INF/classes).
>  >
>  > I'm trying to figure out the best way to do this, using context.xml 
> or external
>  > configuration files (which will need to be deployed and undeployed 
> each time the web-app
>  > get's deployed or undeployed)
>  >
>  > Thx for any help!
>  >
>  > Janek
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > For additional commands, e-mail: users-help@maven.apache.org
>  >
>  >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different context.xml files?

Posted by Mark Hobson <ma...@gmail.com>.
Hi Janek,

Filtering is obviously the best way to achieve this, but we need to
resolve MNG-791 first.

An alternative way which I'm using in the interim is to use profiles. 
You'll need to create multiple versions of your context.xml and
configure the war plugin accordingly, e.g.:

  src
  |_ profiles
    |_ default
      |_ webapp
        |_ META-INF
          |_ context.xml
    |_ live
      |_ webapp
        |_ META-INF
          |_ context.xml
    |_ ...

Then setup your pom with something like:

  <project>
    ...
    <profiles>
      <profile>
        <id>default</id>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-war-plugin</artifactId>
              <configuration>
                <warSourceDirectory>profiles/default/webapp</warSourceDirectory>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      <profile>
        <id>live</id>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-war-plugin</artifactId>
              <configuration>
                <warSourceDirectory>profiles/live/webapp</warSourceDirectory>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      ...
    </profiles>
    ...
  </project>

Then just use "mvn -P<profile> war" to build your war with the given
profile's context.xml, e.g. "mvn -Plive war" for the 'live' profile,
or just use the default with a "mvn war"

Mark

On 24/10/05, Claus, Janek (NIH/NICHD) <cl...@mail.nih.gov> wrote:
> All,
>
> One of the possibilities Tomcat 5.5 suggest for the context configuration of a web
> application is a file named "context.xml" in the META-INF of your webapp.
>
> In my case it declares a datasource, which differs depending on the deployment environment.
>
> Question: how can I use different context.xml for different environments? Filters don't
> work, because the file is not part of "resources", but webapp/META-INF (because, when it's
> part of resources it gets packaged under WEB-INF/classes).
>
> I'm trying to figure out the best way to do this, using context.xml or external
> configuration files (which will need to be deployed and undeployed each time the web-app
> get's deployed or undeployed)
>
> Thx for any help!
>
> Janek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org