You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ziggy <zi...@gmail.com> on 2012/03/06 15:08:11 UTC

Maven - Building a single war file from multiple modules

Note: Also posted at
stackoverflow.com/questions/9584706/maven-building-a-single-java-servlet-based-war-file-from-multiple-modules

I posted a question last week on how i can build dependent modules and the
result was that it was recommended that i use a build tool like Maven or
Ivy. I decided to use Maven to try and achieve what i would like to do. My
project basically builds a single war file which is deployed to Tomcat. The
modules themselves are part of the final war file. Here is an example
structure of the modules

[code]
customerModule
    |-webapp
        |-jsp
            |-customer
                |-findCustomer.jsp
                |-addNewCustomer.jsp
                |-deleteCustomer.jsp
    |-src
        |-com
            |-mycompany
                |-customer
                    |-FindCustomerAction.java
                    |-AddCustomerAction.java
                    |-DeleteCustomer.java
[/code]

[code]
productModule
    |-webapp
        |-jsp
            |-product
                |-productCustomer.jsp
                |-addNewProduct.jsp
                |-deleteProduct.jsp
    |-src
        |-com
            |-mycompany
                |-product
                    |-FindProductAction.java
                    |-AddProductAction.java
                    |-DeleteProduct.java
[/code]

[code]
commonModule
    |-webapp
        |-css
            |-style.css
        |-jsp
            |-templates
                |-coreTemplate.jsp
    |-src
        com
            |-mycomany
                |-common
                    |-Logger.java
                    |-Access.java
    |-META-INF
        |-MANIFEST.MF
        |-context.xml
    |-WEB-INF
        |-lib
            |-oraclejdbc.lib
            |-log4j.lib
            |-common.lib
        |-struts-config.xml
        |-tiles-def.xml
        |-web.xml
[/code]

As you can probably see, the above will all collectively form one
application. What i would like to do is to end up with an artifact for each
module. Because of the mixture of file types(jsp,css,java) i am not quite
sure what is a suitable artifact. The diagram below show the structure of
the war file i would like to end up with.

[code]
MyApp.war
    |-webapp
        |-css
            |-style.css
        |-jsp
            |-customer
                |-findCustomer.jsp
                |-addNewCustomer.jsp
                |-deleteCustomer.jsp
            |-product
                |-productCustomer.jsp
                |-addNewProduct.jsp
                |-deleteProduct.jsp
            |-templates
                |-coreTemplate.jsp
    |-META-INF
        |-MANIFEST.MF
        |-context.xml
    |-WEB-INF
        |-lib
            |-oraclejdbc.lib
            |-log4j.lib
            |-common.lib
            |-customerModule.jar
            |-productModule.jar
        |-classes
            |-com
                |-mycomany
                    |-common
                        |-Logger.class
                        |-Access.class
        |-struts-config.xml
        |-tiles-def.xml
        |-web.xml
[/code]

A couple of notes
    - The java files in commonModule are built and end up in WEB-INF/classes
    - The java files for the customerModule end up as a jar file in
WEB-INF/lib
    - The java files for the productModule end up as a jar file in
WEB-INF/lib
    - All of the jsps,css end up in the root of the war file

What is the best way i should store the artifact for each module in the
repository?

- I could use a jar file but this cant hold the html type files(jsp,css,js
etc)
- Each module (except the commonModule) will contain a jar file + the jsp,
css files. I am thinking of storing the built artifact as a zip file and
extract it when the MyApp.war is built to build the war file?
- Can i store the artifact for each module as a war file even though only
one has a web.xml file?

How can i implement this using Maven

- I have been investigating Maven and found that it might be possible to
have a multi module project with the following structure

MyApp.pom (parent project)
    commonModule.pom
    customer.pom
    product.pom

- If i zipped up the modules in the repository how would i refer to them
from the parent project and unzip them to build the final war file?
- Is it possible to automatically trigger the build of the parent project
if any of the child projects are built?
- I havent figured out how to maintain the version of each of the child
projects. If i build the customer project, how does the parent project know
that there is a newer version of the customer.zip (or .jar) in the
repository?
- Assuming the repository currently contains the following

[code]
    |-productModule.v.0.1.zip
    |-customerModule.v.0.1.zip
    |-commonModule.v.0.1.zip
[/code]

    If i rebuild, the customerModule and then rebuild the war file buy
building the parent project, does maven rebuild all of the other modules in
the repository even if they have not changed? How exactly will this work?

Is there an example project anywhere that demonstrate how to achieve the
above? Any links or resources which show an example of the above would be
very usefull.

Re: Maven - Building a single war file from multiple modules

Posted by Ron Wheeler <rw...@artifact-software.com>.
A video on how to create a multi-module project in Eclipse and Maven.



http://www.lordofthejars.com/2012/02/for-everything-i-long-to-do-no-matter.html

Ron


On 06/03/2012 11:46 AM, Ron Wheeler wrote:
> There are lots of ways to skin the cat.
>
> We try to do the following:
> Most of the code goes in projects that generate JAR files. These are 
> divided up into functional units as much as possible(customers).
> The war project contains all of the JSPs,XML,  CSS, etc. and depends 
> on the external JAR files (oraclejdbc.lib,etc.) and your JAR libraries 
> (customer.jar, product.jar).
> The war project has the WEB-INF structure in the form that the servlet 
> needs when delivered.
> Maven does not need any special instructions to build this. It knows 
> how to assemble jars and wars that work.
>
> Ron
>
>
>
> On 06/03/2012 9:08 AM, Ziggy wrote:
>> Note: Also posted at
>> stackoverflow.com/questions/9584706/maven-building-a-single-java-servlet-based-war-file-from-multiple-modules 
>>
>>
>> I posted a question last week on how i can build dependent modules 
>> and the
>> result was that it was recommended that i use a build tool like Maven or
>> Ivy. I decided to use Maven to try and achieve what i would like to 
>> do. My
>> project basically builds a single war file which is deployed to 
>> Tomcat. The
>> modules themselves are part of the final war file. Here is an example
>> structure of the modules
>>
>> [code]
>> customerModule
>>      |-webapp
>>          |-jsp
>>              |-customer
>>                  |-findCustomer.jsp
>>                  |-addNewCustomer.jsp
>>                  |-deleteCustomer.jsp
>>      |-src
>>          |-com
>>              |-mycompany
>>                  |-customer
>>                      |-FindCustomerAction.java
>>                      |-AddCustomerAction.java
>>                      |-DeleteCustomer.java
>> [/code]
>>
>> [code]
>> productModule
>>      |-webapp
>>          |-jsp
>>              |-product
>>                  |-productCustomer.jsp
>>                  |-addNewProduct.jsp
>>                  |-deleteProduct.jsp
>>      |-src
>>          |-com
>>              |-mycompany
>>                  |-product
>>                      |-FindProductAction.java
>>                      |-AddProductAction.java
>>                      |-DeleteProduct.java
>> [/code]
>>
>> [code]
>> commonModule
>>      |-webapp
>>          |-css
>>              |-style.css
>>          |-jsp
>>              |-templates
>>                  |-coreTemplate.jsp
>>      |-src
>>          com
>>              |-mycomany
>>                  |-common
>>                      |-Logger.java
>>                      |-Access.java
>>      |-META-INF
>>          |-MANIFEST.MF
>>          |-context.xml
>>      |-WEB-INF
>>          |-lib
>>              |-oraclejdbc.lib
>>              |-log4j.lib
>>              |-common.lib
>>          |-struts-config.xml
>>          |-tiles-def.xml
>>          |-web.xml
>> [/code]
>>
>> As you can probably see, the above will all collectively form one
>> application. What i would like to do is to end up with an artifact 
>> for each
>> module. Because of the mixture of file types(jsp,css,java) i am not 
>> quite
>> sure what is a suitable artifact. The diagram below show the 
>> structure of
>> the war file i would like to end up with.
>>
>> [code]
>> MyApp.war
>>      |-webapp
>>          |-css
>>              |-style.css
>>          |-jsp
>>              |-customer
>>                  |-findCustomer.jsp
>>                  |-addNewCustomer.jsp
>>                  |-deleteCustomer.jsp
>>              |-product
>>                  |-productCustomer.jsp
>>                  |-addNewProduct.jsp
>>                  |-deleteProduct.jsp
>>              |-templates
>>                  |-coreTemplate.jsp
>>      |-META-INF
>>          |-MANIFEST.MF
>>          |-context.xml
>>      |-WEB-INF
>>          |-lib
>>              |-oraclejdbc.lib
>>              |-log4j.lib
>>              |-common.lib
>>              |-customerModule.jar
>>              |-productModule.jar
>>          |-classes
>>              |-com
>>                  |-mycomany
>>                      |-common
>>                          |-Logger.class
>>                          |-Access.class
>>          |-struts-config.xml
>>          |-tiles-def.xml
>>          |-web.xml
>> [/code]
>>
>> A couple of notes
>>      - The java files in commonModule are built and end up in 
>> WEB-INF/classes
>>      - The java files for the customerModule end up as a jar file in
>> WEB-INF/lib
>>      - The java files for the productModule end up as a jar file in
>> WEB-INF/lib
>>      - All of the jsps,css end up in the root of the war file
>>
>> What is the best way i should store the artifact for each module in the
>> repository?
>>
>> - I could use a jar file but this cant hold the html type 
>> files(jsp,css,js
>> etc)
>> - Each module (except the commonModule) will contain a jar file + the 
>> jsp,
>> css files. I am thinking of storing the built artifact as a zip file and
>> extract it when the MyApp.war is built to build the war file?
>> - Can i store the artifact for each module as a war file even though 
>> only
>> one has a web.xml file?
>>
>> How can i implement this using Maven
>>
>> - I have been investigating Maven and found that it might be possible to
>> have a multi module project with the following structure
>>
>> MyApp.pom (parent project)
>>      commonModule.pom
>>      customer.pom
>>      product.pom
>>
>> - If i zipped up the modules in the repository how would i refer to them
>> from the parent project and unzip them to build the final war file?
>> - Is it possible to automatically trigger the build of the parent 
>> project
>> if any of the child projects are built?
>> - I havent figured out how to maintain the version of each of the child
>> projects. If i build the customer project, how does the parent 
>> project know
>> that there is a newer version of the customer.zip (or .jar) in the
>> repository?
>> - Assuming the repository currently contains the following
>>
>> [code]
>>      |-productModule.v.0.1.zip
>>      |-customerModule.v.0.1.zip
>>      |-commonModule.v.0.1.zip
>> [/code]
>>
>>      If i rebuild, the customerModule and then rebuild the war file buy
>> building the parent project, does maven rebuild all of the other 
>> modules in
>> the repository even if they have not changed? How exactly will this 
>> work?
>>
>> Is there an example project anywhere that demonstrate how to achieve the
>> above? Any links or resources which show an example of the above 
>> would be
>> very usefull.
>>
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



Re: Maven - Building a single war file from multiple modules

Posted by Ron Wheeler <rw...@artifact-software.com>.
There are lots of ways to skin the cat.

We try to do the following:
Most of the code goes in projects that generate JAR files. These are 
divided up into functional units as much as possible(customers).
The war project contains all of the JSPs,XML,  CSS, etc. and depends on 
the external JAR files (oraclejdbc.lib,etc.) and your JAR libraries 
(customer.jar, product.jar).
The war project has the WEB-INF structure in the form that the servlet 
needs when delivered.
Maven does not need any special instructions to build this. It knows how 
to assemble jars and wars that work.

Ron



On 06/03/2012 9:08 AM, Ziggy wrote:
> Note: Also posted at
> stackoverflow.com/questions/9584706/maven-building-a-single-java-servlet-based-war-file-from-multiple-modules
>
> I posted a question last week on how i can build dependent modules and the
> result was that it was recommended that i use a build tool like Maven or
> Ivy. I decided to use Maven to try and achieve what i would like to do. My
> project basically builds a single war file which is deployed to Tomcat. The
> modules themselves are part of the final war file. Here is an example
> structure of the modules
>
> [code]
> customerModule
>      |-webapp
>          |-jsp
>              |-customer
>                  |-findCustomer.jsp
>                  |-addNewCustomer.jsp
>                  |-deleteCustomer.jsp
>      |-src
>          |-com
>              |-mycompany
>                  |-customer
>                      |-FindCustomerAction.java
>                      |-AddCustomerAction.java
>                      |-DeleteCustomer.java
> [/code]
>
> [code]
> productModule
>      |-webapp
>          |-jsp
>              |-product
>                  |-productCustomer.jsp
>                  |-addNewProduct.jsp
>                  |-deleteProduct.jsp
>      |-src
>          |-com
>              |-mycompany
>                  |-product
>                      |-FindProductAction.java
>                      |-AddProductAction.java
>                      |-DeleteProduct.java
> [/code]
>
> [code]
> commonModule
>      |-webapp
>          |-css
>              |-style.css
>          |-jsp
>              |-templates
>                  |-coreTemplate.jsp
>      |-src
>          com
>              |-mycomany
>                  |-common
>                      |-Logger.java
>                      |-Access.java
>      |-META-INF
>          |-MANIFEST.MF
>          |-context.xml
>      |-WEB-INF
>          |-lib
>              |-oraclejdbc.lib
>              |-log4j.lib
>              |-common.lib
>          |-struts-config.xml
>          |-tiles-def.xml
>          |-web.xml
> [/code]
>
> As you can probably see, the above will all collectively form one
> application. What i would like to do is to end up with an artifact for each
> module. Because of the mixture of file types(jsp,css,java) i am not quite
> sure what is a suitable artifact. The diagram below show the structure of
> the war file i would like to end up with.
>
> [code]
> MyApp.war
>      |-webapp
>          |-css
>              |-style.css
>          |-jsp
>              |-customer
>                  |-findCustomer.jsp
>                  |-addNewCustomer.jsp
>                  |-deleteCustomer.jsp
>              |-product
>                  |-productCustomer.jsp
>                  |-addNewProduct.jsp
>                  |-deleteProduct.jsp
>              |-templates
>                  |-coreTemplate.jsp
>      |-META-INF
>          |-MANIFEST.MF
>          |-context.xml
>      |-WEB-INF
>          |-lib
>              |-oraclejdbc.lib
>              |-log4j.lib
>              |-common.lib
>              |-customerModule.jar
>              |-productModule.jar
>          |-classes
>              |-com
>                  |-mycomany
>                      |-common
>                          |-Logger.class
>                          |-Access.class
>          |-struts-config.xml
>          |-tiles-def.xml
>          |-web.xml
> [/code]
>
> A couple of notes
>      - The java files in commonModule are built and end up in WEB-INF/classes
>      - The java files for the customerModule end up as a jar file in
> WEB-INF/lib
>      - The java files for the productModule end up as a jar file in
> WEB-INF/lib
>      - All of the jsps,css end up in the root of the war file
>
> What is the best way i should store the artifact for each module in the
> repository?
>
> - I could use a jar file but this cant hold the html type files(jsp,css,js
> etc)
> - Each module (except the commonModule) will contain a jar file + the jsp,
> css files. I am thinking of storing the built artifact as a zip file and
> extract it when the MyApp.war is built to build the war file?
> - Can i store the artifact for each module as a war file even though only
> one has a web.xml file?
>
> How can i implement this using Maven
>
> - I have been investigating Maven and found that it might be possible to
> have a multi module project with the following structure
>
> MyApp.pom (parent project)
>      commonModule.pom
>      customer.pom
>      product.pom
>
> - If i zipped up the modules in the repository how would i refer to them
> from the parent project and unzip them to build the final war file?
> - Is it possible to automatically trigger the build of the parent project
> if any of the child projects are built?
> - I havent figured out how to maintain the version of each of the child
> projects. If i build the customer project, how does the parent project know
> that there is a newer version of the customer.zip (or .jar) in the
> repository?
> - Assuming the repository currently contains the following
>
> [code]
>      |-productModule.v.0.1.zip
>      |-customerModule.v.0.1.zip
>      |-commonModule.v.0.1.zip
> [/code]
>
>      If i rebuild, the customerModule and then rebuild the war file buy
> building the parent project, does maven rebuild all of the other modules in
> the repository even if they have not changed? How exactly will this work?
>
> Is there an example project anywhere that demonstrate how to achieve the
> above? Any links or resources which show an example of the above would be
> very usefull.
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



Re: Maven - Building a single war file from multiple modules

Posted by Jesse Farinacci <ji...@gmail.com>.
Greetings,

On Tue, Mar 6, 2012 at 9:08 AM, Ziggy <zi...@gmail.com> wrote:
> I posted a question last week on how i can build dependent modules and the
> result was that it was recommended that i use a build tool like Maven

http://maven.apache.org/plugins/maven-war-plugin/overlays.html

-Jesse

-- 
There are 10 types of people in this world, those
that can read binary and those that can not.

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