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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With