简体   繁体   中英

Java Web Application Project development for two clients

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?

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 .

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

Eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM