Hi Janek,

I also use a similar configuration, but I move all the profile-related
files into src/main/profiles, e.g.:

src
|_ main
  |_ filters
    |_ filter.properties
  |_ java
    |_ *.java
  |_ profiles
    |_ default
      |_ filters
        |_ filter.properties
      |_ resources
        |_ ...
    |_ demo
      |_ ...
    |_ live
      |_ ...
  |_ resources
    |_ webapp
      |_ ...
    |_ webapp-filtered
      |_ ...

You can also simplify your pom by using properties, for example here's
mine that uses the above structure:

<project>
        ...
        <build>
                <finalName>${profile.finalName}</finalName>
                <resources>
                        <resource>
                                <directory>src/main/resources</directory>
                        </resource>
                        <resource>
                                
<directory>src/main/profiles/${profile.name}/resources</directory>
                        </resource>
                        <resource>
                                <directory>src/main/webapp-filtered</directory>
                                <targetPath>../${profile.finalName}</targetPath>
                                <filtering>true</filtering>
                        </resource>
                </resources>
                <filters>
                        <filter>src/main/filters/filter.properties</filter>
                        
<filter>src/main/profiles/${profile.name}/filters/filter.properties</filter>
                </filters>
        </build>
        
        <profiles>
                <profile>
                        <id>default</id>
                        <activation>
                                <activeByDefault>true</activeByDefault>
                        </activation>
                        <properties>
                                <profile.name>default</profile.name>
                                <profile.finalName>app</profile.finalName>
                        </properties>
                </profile>
                <profile>
                        <id>demo</id>
                        <properties>
                                <profile.name>demo</profile.name>
                                <profile.finalName>ROOT</profile.finalName>
                        </properties>
                </profile>
                <profile>
                        <id>live</id>
                        <properties>
                                <profile.name>live</profile.name>
                                <profile.finalName>ROOT</profile.finalName>
                        </properties>
                </profile>
        </profiles>
        ...
</project>

Would be good to decide on a standard and document it on the site.

Cheers,

Mark

On 06/11/05, Brett Porter <[EMAIL PROTECTED]> wrote:
> Thanks for this Janek.
>
> I'd encourage people to give thier feedback on this, and if possible
> if someone such as Janek could contribute this as an apt document for
> the website under the guides section, it would be much appreciated.
>
> If you'd like to use wiki.apache.org/maven to collaborate on this, you
> are welcome to.
>
> Regards,
> Brett
>
> On 11/5/05, Claus, Janek (NIH/NICHD) <[EMAIL PROTECTED]> wrote:
> >
> > All,
> >
> > I wanted to give something back to the community. For all of you, who would 
> > like to know
> > how to structure a web application in a way that it can be build for 
> > different
> > environments, here is the solution:
> >
> > I combined several previous posts and my ideas, this application uses 
> > different resources
> > for different environments (profiles) as well as diffenent filters.
> >
> > I filter the context.xml for Tomcat and web.xml, but use totally different 
> > log4j.xml's for
> > the different environments.
> > In addition I have resources that go unfiltered to all environments 
> > (Hibernate
> > configuration files).
> >
> > Create a directory layout similar to this:
> >
> > app
> > |
> > +- src
> >      |
> >      +- main
> >          |
> >          +- filter
> >          |   |
> >          |   +- dev (filter properties for your local development)
> >          |   |
> >          |   +- prod (filter props for production)
> >          |
> >          +- java
> >          |
> >          +- resources
> >          |   |
> >          |   +- all (resources for all environments)
> >          |   |
> >          |   +- dev
> >          |   |
> >          |   +- prod
> >          |
> >          +- webapp
> >          |
> >          +- webapp-filtered
> >              |
> >              +- META-INF (e.g. context.xml)
> >              |
> >              +- WEB-INF (e.g. web.xml)
> >
> > Your pom should look something like this then:
> >
> > ...
> >
> >    <build>
> >      <finalName>app</finalName>
> >      <resources>
> >         <!-- Resources for all builds. -->
> >         <resource>
> >           <directory>src/main/resources/all</directory>
> >         </resource>
> >      </resources>
> >     </build>
> >
> >    <profiles>
> >      <!-- Local development environment. -->
> >      <profile>
> >        <id>dev</id>
> >        <activation>
> >          <activeByDefault>true</activeByDefault>
> >        </activation>
> >        <build>
> >          <resources>
> >            <resource>
> >              <directory>src/main/resources/dev</directory>
> >            </resource>
> >            <resource>
> >              <directory>src/main/webapp-filtered</directory>
> >              <targetPath>../app</targetPath>     <!-- has to be finalName! 
> > -->
> >              <filtering>true</filtering>
> >            </resource>
> >          </resources>
> >          <filters>
> >            <filter>src/main/filter/dev/context.properties</filter>
> >            <filter>src/main/filter/dev/web.properties</filter>
> >          </filters>
> >        </build>
> >      </profile>
> >
> >      <!-- Production. -->
> >      <profile>
> >        <id>prod</id>
> >        <build>
> >          <resources>
> >            <resource>
> >              <directory>src/main/resources/prod</directory>
> >            </resource>
> >            <resource>
> >              <directory>src/main/webapp-filtered</directory>
> >              <targetPath>../app</targetPath>     <!-- has to be finalName! 
> > -->
> >              <filtering>true</filtering>
> >            </resource>
> >          </resources>
> >          <filters>
> >            <filter>src/main/filter/prod/context.properties</filter>
> >            <filter>src/main/filter/prod/web.properties</filter>
> >          </filters>
> >        </build>
> >      </profile>
> >
> >    </profiles>
> >
> > ...
> >
> > Would be great if we could use ${pom.build.finalName}! Maybe this is an 
> > idea for the Maven
> > developers.
> >
> > Using this you can build your dev app using:
> > mvn package (since it is the default) or mvn -Pdev package
> >
> > and your production application using:
> > mvn -Pprod package
> >
> > This can be extended. Just add another directory and profile and you're 
> > done!
> >
> > I found this to be a good way of attacking the problem. Feedback is welcome!
> >
> >
> > Janek
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to