I have a Maven project with a parent-pom project and 3 maven-module projects in it. 2 of the modules are Java-EE web apps that compile into WAR files. 1 of the modules contains common JAVA code which is shared between the 2 other projects. Sharing the JAVA code was easy.
The question I have is how to a share common static resources such as JavaScript, CSS, and image files without duplicating them in each web module? I would also like to do it in such a way that I can continue running the web app from Eclipse and have changes I make to the static-files automatically available to the Eclipse's running server.
Try this:
1.
|-- pom.xml
|-- appsweb1 (war)
|-- appsweb2 (war)
|-- common (jar)
|-- src/main/java
|-- src/static_files
|-- pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<id>default-copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>false</overwrite>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/static_files</outputDirectory>
<resources>
<resource>
<directory>../common/src/main/static_files</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Documentation on the Maven Resources Plugin: https://maven.apache.org/plugins/maven-resources-plugin/
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