views:

81

answers:

2

Hi, I'm developing a web-project based on Spring (MVC), Hibernate, PostgreSQL (using Maven). Now I'm trying to get a new customer who requires some differences in several parts of the application. I've read the Maven Definitive Guide from Sonatype to get a feeling about Multi-modules Maven Projects but one of my most important questions has not been answered there: How can I share common view-components over several modules/projects and integrate them depending on the customer I want to build for? The Service-Layer is pretty clear but I can't figure out how to share jsp/jspf files and merge them with the custom files when building the specific customer-module (which then depends on the common-module).

How would you try to avoid just simply cloning the commonly used code?

+3  A: 

You can put common components in a library project and unpack them as needed using dependency:unpack or dependency:unpack-dependencies

E.g. you project layout would be like that:

root
 |____ common-lib (jar, contains common java code)
 |____ common-gui (jar, contains only non-java stuff like js, jsp, css etc) 
 |____ client1    (war)
 |____ client2    (war)

client1 and client2 would each have a regular compile dependency to common-lib, but only a provided dependency to common-gui (if you use dependency:unpack it doesn't have to be a project dependency at all)

Now you'd add code like this to your client projects:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-common-gui-elements</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.yourcompany</groupId>
                        <artifactId>common-gui</artifactId>
                        <version>${project.version}</version>
                        <type>jar</type>
                        <!--  war assembly directory -->
                        <outputDirectory>
                            ${project.build.directory}/${project.build.finalName}
                        </outputDirectory>
                        <includes>**/*.jsp,**/*.css,**/*.js</includes>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

That way you can re-use your components but you can always choose yourself which components you distribute to which client.

seanizer
This is another way and can be useful too so +1. It reminds me of [How to share resources across projects in Maven](http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/).
Pascal Thivent
+4  A: 

I can't figure out how to share jsp/jspf files and merge them with the custom files when building the specific customer-module (which then depends on the common-module).

This looks like a good use case for Overlays.

Pascal Thivent
I agree (+1) ...
seanizer