Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 552
velaia Avatar asked Sep 22 '10 06:09

velaia


People also ask

Can I develop web application using Java?

JavaServer Pages (JSP) technology provides a simplified, fast way to create dynamic web content. JSP technology enables rapid development of web-based applications that are server- and platform-independent. JSP technology lets you add snippets of servlet code directly into a text-based document.

Which Java Edition is used to develop web-based applications?

J2SE(Java Platform, Standard Edition) Also termed as Core Java, this is Java most basic and standard version. It's the cleanest version of Java, a basic foundation for all other editions. J2SE is usually taken into consideration to build web applications for the Desktop environment.


2 Answers

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.

like image 83
Pascal Thivent Avatar answered Oct 03 '22 15:10

Pascal Thivent


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.

like image 28
Sean Patrick Floyd Avatar answered Oct 03 '22 17:10

Sean Patrick Floyd