Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing static resources between maven modules

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.

like image 696
Eric Avatar asked Oct 13 '15 07:10

Eric


1 Answers

Try this:

1.

 |-- pom.xml
    |-- appsweb1 (war)
    |-- appsweb2 (war)
    |-- common (jar)
        |-- src/main/java
        |-- src/static_files
        |-- pom.xml
  1. Add in pom appsweb1, appsweb2, or add it in pom parent and just add groupId, artifactId in child:
<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/

like image 56
question_maven_com Avatar answered Sep 21 '22 07:09

question_maven_com