Fabio
Fabio

Reputation: 545

Publish filtered web.xml on eclipse tomcat

I've a Maven web application developed with Eclipse, in my pom.xml file I've defined 2 different profiles: production and development, with different properties. When I do a clean install to create my WAR bundle, thanks to filteringDeploymentDescriptors in my maven-war-plugin I manage to have a parsed web.xml with all the properties correctly substituted.

The problem is when I publish my webapp to the built in Eclipse tomcat that I'm using, that way the web.xml isn't parsed at all and I have all raw properties name.

I've set activeByDefault to true in my development profile and I've also set the Active Maven Profile (Properties >> Maven), but I still can't get it to work.

Upvotes: 0

Views: 773

Answers (1)

Little Santi
Little Santi

Reputation: 8823

I think of this solution:

The idea is to change your application's web root path for Eclipse:

  1. Close your project in Eclipse.
  2. Open in an external editor the <project>/.settings/org.eclipse.wst.common.component file.
  3. Set the defaultRootSource as:

  4. Open in an external editor the <project>/pom.xml file.

  5. Add within the <build> tag:

    <resources>
        <resource>
            <directory>src/main/webapp</directory>
            <filtering>false</filtering>
            <targetPath>../../target/m2e-wtp/web-resources</targetPath>
            <excludes>
                <exclude>WEB-INF</exclude>
            </excludes>
        </resource>
    </resources>
    
  6. Open your project in Eclipse and try it.

With this scheme, you get that Eclipse keeps your project automatically built, and on every build it calls Maven to do the resources filtering. Then, Maven does a double filtering:

  • The web.xml (by the filteringDeploymentDescriptors=true).
  • The rest ot src/main/webapp files (by the <resources> tag). ... And the result will be outputed to the target/m2e-wtp/web-resources directory, which is now the place where Eclipse hopes to find the web resources.

WARN: There is just one drawback: You shall not execute your JSPs from src/main/webapp, because that is no more a web container directory. Instead, you should open a browser and enter the URL you want to open.

I tried it with "build automatically" turned on, and it worked: I executed a JSP which reads init parameters from web.xml, and I also executed clean package and it produced a right war.

Upvotes: 0

Related Questions