Quantcast

using build profiles for WAR plugin

classic Classic list List threaded Threaded
38 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

using build profiles for WAR plugin

offbyone
I am trying to create different WAR builds using profiles for my different
production sites.  Each site requires different configuration files.  I
think I am confused on how to use build profiles.

My plan was this:
1)Create a base configuration for the war plugin that includes my basic
configuration:

<build>
.
.
.
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <webResources>
                        <resource>

<directory>${basedir}/src/main/conf/server</directory>
                            <includes>
                                <include>log4j.xml</include>
                            </includes>
                            <targetPath>WEB-INF/classes</targetPath>
                        </resource>
                        <resource>

<directory>${basedir}/src/main/reports</directory>
                            <targetPath>WEB-INF/reports</targetPath>
                        </resource>
                        <resource>

<directory>${basedir}/src/main/baseconf</directory>
                            <targetPath>WEB-INF</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>


2)Now I need to add the special configuration for each production site so I
create a profile with each with additional configuration files:



<profiles>
        <profile>
            <id>site1</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <webResources>
                                <resource>

<directory>${basedir}/src/main/conf/server/production-site-1</directory>
                                    <targetPath>WEB-INF</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>site2</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <webResources>
                                <resource>

<directory>${basedir}/src/main/conf/server/production-site-2</directory>
                                    <targetPath>WEB-INF</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


3)mvn clean install war:war -o -Psite1

This doesn't work.  The war file gets built with the base configuratio
files but the special configuration items in the profile don't get moved
over.

The output actually says it is copying those files over but I dont' see
them.  I wonder if they then get deleted?

My understanding was that the profile would add additional resources to
those already configured in the base build.  Is that behavior incorrect?

Do I need to redo the entire webResources section in the profile?

thanks
-ryan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Wayne Fay
> I am trying to create different WAR builds using profiles for my different
> production sites.  Each site requires different configuration files.  I
> think I am confused on how to use build profiles.

Don't do this. Build a WAR file that can be deployed on any server and
will run properly with no changes. Use JNDI, System properties, WAR
App server parameters/configuration, or another system to externalize
those system configuration differences.

Read Stephen Connolly's post from about 10hrs ago in this recent
thread on this mailing list for more options and discussion -- How to
deploy with 'classifier'

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
I have no interest in using JNDI.  Could someone please address my question regarding profiles?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

stephenconnolly
Read the thread I posted... JNDI is not the only solution. Profiles is
*NOT* the solution

On 29 February 2012 21:32, offbyone <[hidden email]> wrote:

> I have no interest in using JNDI.  Could someone please address my question
> regarding profiles?
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5526140.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Ansgar Konermann
In reply to this post by offbyone
Am 29.02.2012 22:33 schrieb "offbyone" <[hidden email]>:
>
> I have no interest in using JNDI.

You certainly don't need to. Pick any mechanism you like to configure your
application according to the needs of your runtime environment, as long as
you do it by configuration at *runtime* (not compile time).

Would Microsoft sell a " Windows 7 for networks having their DNS server at
192.168.1.1" and bake this information into win32.sys on  their product
DVDs? Certainly not. They sell "Windows 7" and let you configure the DNS
server address at runtime.

If you really want to create stage specific rollout artifacts using maven,
that's also okay, but it's best handled as different modules. Each module
would include the common artifacts like jars etc. and put it into a zip
file or rpm or whatever you like, and ultimately add the stage-specific
configuration *data* which is later used by the application.

>  Could someone please address my question
> regarding profiles?

Maven profiles are intended to be used to make your build working in
different *build* contexts. Examples: use host xy as repository manager
when building at work, use abc when at home.

Don't use them to differentiate between different *runtime* environments of
the application you are building. Keep your artifacts independent of
application configuration as far as possible.

Just my 0.02€

Best

Ansgar

>
> --
> View this message in context:
http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5526140.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
In reply to this post by stephenconnolly
I am trying to understand how profiles work.  I don't want to use classifiers for this as this has nothing to do with my environment which is identical but rather my deployment needs.  

Could someone please explain what I am missing about profiles?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
In reply to this post by Ansgar Konermann
Thanks for the reply.  

Unfortunately all the documentation I have seen point to profiles for this tool.  If profiles are not used to differentiate runtime configuration changes, then what are?  Can you point me to some documentation?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Ron Wheeler
Everyone else has to deal with this situation.
Your concerns are not unique.
Everyone has production, development and maintenance to deal with.
A lot of applications of each type standalone, web, etc., have been
built by many companies and development teams.

You have been told the correct way to handle this.

If you want to do it in the wrong way and misuse the features of maven,
you can.
No one will stop you.
You have been warned that it will not work but you can try as long as
you like.

It should be clear that the best minds in the Maven world (the guys who
wrote it and maintain it) have given you their best advice.

Why not try it the "right" way once and see if you like it. At least you
will get help.
Some of the suggestions are very easy to try. A few minutes of editing a
few POMs.

Ron

On 29/02/2012 6:04 PM, offbyone wrote:

> Thanks for the reply.
>
> Unfortunately all the documentation I have seen point to profiles for this
> tool.  If profiles are not used to differentiate runtime configuration
> changes, then what are?  Can you point me to some documentation?
>
>
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5526330.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Ron Wheeler
President
Artifact Software Inc
email: [hidden email]
skype: ronaldmwheeler
phone: 866-970-2435, ext 102




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Sebastian Otaegui
One of the uses of profiles is to have different maven runtime
configurations for running different plugin configurations based on them.

See these examples
https://github.com/jbossas/jboss-as/blob/master/pom.xml
https://github.com/jboss/jboss-parent-pom/blob/master/pom.xml

If you still insist on doing what you are saying one option is to do a
multimodule project.

like this:

- top level (parent pom where you define your modules)
          ---------  your "vanilla" war (your "real" webapp)
          ---------  your "qa" war
          ---------  your "prod" war

both the "qa" and "prod" war are built using the maven-war-plugin with the
overlay feature.
http://maven.apache.org/plugins/maven-war-plugin/examples/war-overlay.html

The people that maintains CAS (JASIG) are using that methodology.

On Wed, Feb 29, 2012 at 10:10 PM, Ron Wheeler <
[hidden email]> wrote:

> Everyone else has to deal with this situation.
> Your concerns are not unique.
> Everyone has production, development and maintenance to deal with.
> A lot of applications of each type standalone, web, etc., have been built
> by many companies and development teams.
>
> You have been told the correct way to handle this.
>
> If you want to do it in the wrong way and misuse the features of maven,
> you can.
> No one will stop you.
> You have been warned that it will not work but you can try as long as you
> like.
>
> It should be clear that the best minds in the Maven world (the guys who
> wrote it and maintain it) have given you their best advice.
>
> Why not try it the "right" way once and see if you like it. At least you
> will get help.
> Some of the suggestions are very easy to try. A few minutes of editing a
> few POMs.
>
> Ron
>
>
> On 29/02/2012 6:04 PM, offbyone wrote:
>
>> Thanks for the reply.
>>
>> Unfortunately all the documentation I have seen point to profiles for this
>> tool.  If profiles are not used to differentiate runtime configuration
>> changes, then what are?  Can you point me to some documentation?
>>
>>
>>
>> --
>> View this message in context: http://maven.40175.n5.nabble.**
>> com/using-build-profiles-for-**WAR-plugin-tp5525954p5526330.**html<http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5526330.html>
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<[hidden email]>
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>
> --
> Ron Wheeler
> President
> Artifact Software Inc
> email: [hidden email]
> skype: ronaldmwheeler
> phone: 866-970-2435, ext 102
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Those who do not understand Unix are condemned to reinvent it, poorly.
Any sufficiently recent Microsoft OS contains an ad hoc,
informally-specified, bug-ridden, slow implementation of half of Unix.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
In reply to this post by Ron Wheeler
I appreciate the feedback, but I am struggling to follow, clearly I don't understand "the maven way".

I am new to maven, based on the documentation and the specification it seems like profiles are used to create different versions of a deployment package.  Why would profiles be there if not for that purpose?  

More importantly, why would maven have such a rich properties and resource filtering feature set if the maven way is to externalize all this information?  

Maven is suppose to be a build tool, but you are telling me I shouldn't put build configuration data in it.  It seems like you guys are saying only to use the dependency management/repository aspect of it.

Would love some clarification.
thanks



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Ron Wheeler
Do not touch profiles until you have your build working without them.

As near as I can tell from the traffic here, they are intrinsically evil
and should only be used in very specific situations.
They are not used for "normal" software projects.
They are not suitable for new Maven users.
They will lead you down the path to Maven hell and cause you no end of
heartache.

Ron


On 01/03/2012 1:30 PM, offbyone wrote:

> I appreciate the feedback, but I am struggling to follow, clearly I don't
> understand "the maven way".
>
> I am new to maven, based on the documentation and the specification it seems
> like profiles are used to create different versions of a deployment package.
> Why would profiles be there if not for that purpose?
>
> More importantly, why would maven have such a rich properties and resource
> filtering feature set if the maven way is to externalize all this
> information?
>
> Maven is suppose to be a build tool, but you are telling me I shouldn't put
> build configuration data in it.  It seems like you guys are saying only to
> use the dependency management/repository aspect of it.
>
> Would love some clarification.
> thanks
>
>
>
>
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5528742.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Ron Wheeler
President
Artifact Software Inc
email: [hidden email]
skype: ronaldmwheeler
phone: 866-970-2435, ext 102




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Wayne Fay
In reply to this post by offbyone
> I am new to maven, based on the documentation and the specification it seems
> like profiles are used to create different versions of a deployment package.
> Why would profiles be there if not for that purpose?

Opinions have changed on this point through the years. Maven is
opinionated software.

Modern QA best practices demand that the development team deliver an
artifact to QA and that same unchanged artifact is then delivered to
UAT and Production.

By creating environment- or server-specific artifacts, you are
introducing the possibility of errors into this process. There is a
chance that Maven did something wrong (javac failed, bits got flipped
in your ram since you're not using ECC, etc) when constructing the
PROD artifact but built DEV and QA just fine. You would have no idea
that you are about to deploy a horribly corrupted artifact to PROD
until it was done and your "five nines SLA" is suddenly in trouble.
This defeats the entire purpose of QA.

> Maven is suppose to be a build tool, but you are telling me I shouldn't put
> build configuration data in it.  It seems like you guys are saying only to
> use the dependency management/repository aspect of it.

Build configuration -- yes.

Server-specific runtime configuration which locks a particular
artifact so it only runs without modifications in one environment --
no.

Some people include "all" runtime configurations in one package and
then use a variety of techniques to tell their code which
configuration to load at runtime. There are other ways of doing the
same general thing, you are free to pick one which seems the most
reasonable to you.

Profiles for this purpose are nearly always the WRONG answer. Make
your build work WITHOUT profiles.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
Ok, I hear you, profiles are evil.  BUT I still don't understand the alternative so let me give a specific and tangible example and maybe you can explain a specific alternative.

I am currently deploying my product in a tomcat/linux environment as a war file.  My webapp is driven by a set of spring configuration files using the Spring context loader.  For example, one of those spring configuration files is called LookAndFeel.xml.  It sets attributes like colors of the user interface.  I love using this type of configuration driven design because it lets me swap out the entire look and feel just by changing a config file.

There are many deployments of my application on different systems and each one has a different look and feel configuration file.  So, I was planning to have a different maven profile for each deployment and have the profile automatically push the correct LookAndFeel.xml into the war archive.

So specifically how do I accomplish this this in maven without using profiles?  
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Wayne Fay
> There are many deployments of my application on different systems and each
> one has a different look and feel configuration file.  So, I was planning to
> have a different maven profile for each deployment and have the profile
> automatically push the correct LookAndFeel.xml into the war archive.
>
> So specifically how do I accomplish this this in maven without using
> profiles?

Multimodules + WAR overlays = each will have its own GAV and no profiles

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Ron Wheeler
In reply to this post by offbyone
This is not a unique situation.
Many people here use Spring and most people have to generate different
WAR files.
One way is to have a set of maven JAR projects that contain all the code
and a set of WAR projects that depend on your JARS and contain the
Spring configuration files that are specific to each customer.

Each WAR file will have all of the right code with the right
configuration files and will build nicely with very simple pom files
that are easy to maintain.

Once you get this working, you can automate the maintenance of the WAR
projects to handle new releases.

This will work and you will have your setup done and working in an hour
or less.

It will also work for each new release of Maven and you will be able to
get support here easily since this is the Maven way and we all know how
to do this.


Ron


On 01/03/2012 2:16 PM, offbyone wrote:

> Ok, I hear you, profiles are evil.  BUT I still don't understand the
> alternative so let me give a specific and tangible example and maybe you can
> explain a specific alternative.
>
> I am currently deploying my product in a tomcat/linux environment as a war
> file.  My webapp is driven by a set of spring configuration files using the
> Spring context loader.  For example, one of those spring configuration files
> is called LookAndFeel.xml.  It sets attributes like colors of the user
> interface.  I love using this type of configuration driven design because it
> lets me swap out the entire look and feel just by changing a config file.
>
> There are many deployments of my application on different systems and each
> one has a different look and feel configuration file.  So, I was planning to
> have a different maven profile for each deployment and have the profile
> automatically push the correct LookAndFeel.xml into the war archive.
>
> So specifically how do I accomplish this this in maven without using
> profiles?
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5528917.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Ron Wheeler
President
Artifact Software Inc
email: [hidden email]
skype: ronaldmwheeler
phone: 866-970-2435, ext 102




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
Ok so I should create a base pom with a war configuration and then a separate pom for each site that depends on this with overlays to add the extra configuration file.
I will try.

If I am interpreting your comments correctly, profiles allow for a user to flaten a maven build deployment, but this is a bad practice and it is better to make your maven structure deep.

So are profiles going to be deprecated?   I would think I am not alone in getting turned down the wrong path because most of the documentation/howtos I have found point to using profiles.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Ron Wheeler
On 01/03/2012 2:43 PM, offbyone wrote:

> Ok so I should create a base pom with a war configuration and then a separate
> pom for each site that depends on this with overlays to add the extra
> configuration file.
> I will try.
>
> If I am interpreting your comments correctly, profiles allow for a user to
> flaten a maven build deployment, but this is a bad practice and it is better
> to make your maven structure deep.
>
> So are profiles going to be deprecated?   I would think I am not alone in
> getting turned down the wrong path because most of the documentation/howtos
> I have found point to using profiles.
There are some uses for profiles that seem harmless so it is a
documentation issue.

It is fairly common in Apache documentation for the programmers to make
a big deal about all the wonderful things that the package can do.
They are not particularly concerned about "Best Practices".

The most common usage is often left out of the documentation since it is
"dull" or not very impressive.
This sometimes means that obscure usage of features or seldom used
features are heavily documented while the main use case is  not described.

New Maven users often fall into the trap that you were headed into.

A really simple "Best Practice" that most people use, is hard to find in
the documentation while an obscure "Worst Practice" is described because
it shows how clever the software developers are and how powerful the
product is.

There should be a "Best Practice" section on the Maven site describing
the best way to implement the common software development patterns.

There are not really a lot of cases to consider but every new Maven user
has to sort out their own case.

Ron


> --
> View this message in context: http://maven.40175.n5.nabble.com/using-build-profiles-for-WAR-plugin-tp5525954p5528994.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Ron Wheeler
President
Artifact Software Inc
email: [hidden email]
skype: ronaldmwheeler
phone: 866-970-2435, ext 102




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Manfred Moser
In reply to this post by Wayne Fay
On Thu, March 1, 2012 11:19 am, Wayne Fay wrote:

>> There are many deployments of my application on different systems and
>> each
>> one has a different look and feel configuration file.  So, I was
>> planning to
>> have a different maven profile for each deployment and have the profile
>> automatically push the correct LookAndFeel.xml into the war archive.
>>
>> So specifically how do I accomplish this this in maven without using
>> profiles?
>
> Multimodules + WAR overlays = each will have its own GAV and no profiles

Completely agree. You can even do that with externally provided war files
that you customize..

manfred

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

offbyone
In reply to this post by Ron Wheeler
Really struggling here and could use some help with these overlays.  I seem to be missing basic concepts or maybe I am just slow, sorry if these questions are pedestrian.

So I am trying to produce an overlay to add the extra configuration for each of my server deployments.  

I have my main project which is a package pom type.  It has dependencies, a compiler plugin and a war plugin.  Essentially:

project directory layout
/pom.xml
..src/main/java
..src/main/webapp
..src/main/reports


<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myproject</groupId>
    <artifactId>myartifact</artifactId>
    <version>8.1.1</version>
    <name>my project</name>
    <packaging>pom</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/reports</directory>
                            <targetPath>WEB-INF/reports</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
    </build>
    <dependencies>
        .
        .
        .
    </dependencies>
</project>

I can compile and execute the war task to create the war.  It of course is missing my per server files.  I presume this is correct so far, but please let me know if I am already blowing it.

Then I have my other projects for each server:

project directory layout
/pom.xml
..src/main/java
..src/main/webapp
..src/main/reports

..server/server1
..server/server1/pom.xml
..server/server1/src/main/webapp

..server/server2
..server/server2/pom.xml
..server/server3/src/main/webapp

..server/server3
..server/server3/pom.xml
..server/server3/src/main/webapp


Each of these poms looks like this(clearly something is wrong):
<project>
    <modelVersion>4.0.0</modelVersion>
    <parent> //??? Am I suppose to be referencing the main project as a parent?
            <groupId>com.myproject</groupId>
            <artifactId>myartifact</artifactId>
            <version>8.1.1</version>
    </parent>
    <groupId>com.myproject</groupId>
    <artifactId>server1</artifactId>
    <version>8.1.1</version>
    <packaging>war</packaging>

    <dependencies>
    <dependency>  //???Am I suppose to be referencing the main project as a dependency here?
            <groupId>com.myproject</groupId>
            <artifactId>myartifact</artifactId>
            <version>8.1.1</version>
    </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>com.myproject</groupId>
                            <artifactId>myartifact</artifactId>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>



I get some dependency error that I don't understand.  I am unclear as to the relationship of the two projects.
Does the main project reference the overlay or vice versa?  

Do I need to set a dependency in the overlay to the other project or vice versa?


Also, what are the steps I am suppose to go through to get this built?  
I am presuming that I install the first project, then package the second project?  This is a lot more work than when I used the profiles which was a one command process, am I missing something?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using build profiles for WAR plugin

Wayne Fay
> I have my main project which is a package pom type.  It has dependencies, a
> compiler plugin and a war plugin.  Essentially:

This is most likely wrong. Your war projects should use package 'war".

Here is how I would structure this:
top-parent project, packaging pom
module lib with its own pom, packaging jar
module generic-war with its own pom, packaging war, depends on lib
module clienta-war with its own pom, packaging war, depends on generic-war
module clientb-war with its own pom, packaging war, depends on generic-war

Generally you should put all your source code in a module with
packaging jar. You probably want to put code in your War module but
this is not a best practice. I suggested a "lib" jar module above, but
feel free to add more as needed and set up dependencies between them.
These jars are dependencies for your wars.

Then you have a generic-war module with packaging war. This is your
"overlay base".

Then you have client- or environment-specific modules with packaging
war that depend on your generic-war base. By simply specifying the
generic-war as a dependency of these war artifacts, your wars will
automatically get overlaid.

Here's more info and examples that I won't get into here:
http://maven.apache.org/plugins/maven-war-plugin/examples/war-overlay.html

All of these modules should have their own unique artifactIds but they
can share one groupId if that is your preference.

> I can compile and execute the war task to create the war.  It of course is
> missing my per server files.  I presume this is correct so far, but please
> let me know if I am already blowing it.

You are already blowing it. ;-)

You should just be able to type "mvn package" and if the project is a
packaging war, it will automatically pull in the war plugin and create
a war file as output. You should not be specifying "mvn war:war" or
other such commands. The war plugin "knows" when it should execute for
packaging war projects.

>    <parent> //??? Am I suppose to be referencing the main project as a
> parent?

Generally yes you should have 1 top parent and optionally multiple
levels of parents on down to the leaf projects which are jar, war,
ear, and other packaging types.

>    <dependency>  //???Am I suppose to be referencing the main project as a
> dependency here?

This is discussed in depth above.

>                <configuration>
>                    <overlays>
>                        <overlay>
>                            <groupId>com.myproject</groupId>
>                            <artifactId>myartifact</artifactId>

This is should only be necessary if the war module does not list the
overlaid war as a dependency, as I suggested above. You should remove
this.

> I get some dependency error that I don't understand.  I am unclear as to the
> relationship of the two projects.
> Does the main project reference the overlay or vice versa?

Draw up your project on a piece of paper. Sort out the dependencies
topographically. The leaf nodes are where overlays should be
happening.

> Also, what are the steps I am suppose to go through to get this built?
> I am presuming that I install the first project, then package the second
> project?  This is a lot more work than when I used the profiles which was a
> one command process, am I missing something?

You should be able to execute a single "mvn package" command from the
top parent and it should build all of the modules in the proper order
resulting in one or more overlaid war files as you expect.

Honestly you need to slow down, read more documentation, and build
some basic sample projects to have a better handle on the "basics" you
are missing before trying to make this work -- you're dealing with
some advanced concepts and techniques. Here are some suggested
resources:
http://maven.apache.org/articles.html

You are trying to just jump into Maven 201 without doing Maven 101
first. Slow down, do it right, and everything will make more sense to
you.

Wayne

PS- Your note to Ron was not private, if that was your intention.
PPS- Nabble is crap. Please just subscribe to the list via email.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

12
Loading...