开发者

Java Web Application Project development for two clients

开发者 https://www.devze.com 2023-01-16 22:31 出处:网络
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

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-开发者_如何学Cmodules 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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消