Preventing XML overrides in Tomcat 6

I am using JNDI to read the database configuration from my application context.xml. The way I currently have this setup is to have [appname] .xml in conf / Catalina / localhost. However, when I redeploy the application, this file is overridden by an empty context file and I have to copy it back to the conf / Catalina / localhost directory. I have different database settings etc. For my test and production servers, so I don't want to put the context file in META-INF in the WAR file, but I would just like to store it in conf / Catalina / localhost directory. Is this possible?

Somewhere better to place the database configuration?

I would also like to avoid setting the config in the server.xml file, although I know this is possible.

Thank!

+3


source to share


2 answers


I would say that one needs to use maven profiles (one for prod, one for test) and have different resource definitions for each profile. You can store your shared files in src / main / resources and then have a folder for each profile type to store specific config files:

  • Src / test / resources
  • Src / prod / resources

Then you can modify your pom to define each profile and associated resources:



<project>
  <profiles>
    <profile>
      <id>prod</id>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
          </resource>
          <resource>
            <directory>src/prod/resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
          </resource>
        </resources>
      </build>
    </profile>

    <profile>
      <id>test</id>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
          </resource>
          <resource>
            <directory>src/test/resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
          </resource>
        </resources>
      </build>
    </profile>
  </profiles>
</project>

      

Finally, you can build a war using the -Pprod or -Ptest profile argument for mvn

mvn -Pprod package

      

0


source


The problem is that undeploy deleted the specific context.xml file of the webapp that was installed in Catalina / localhost / .xml



If you don't want the file to be deleted, you just need to redeploy it, not expand / expand

0


source







All Articles