I have a maven project with a module which is a java web application (A module) and another module (B module) that is also a java web application that uses the classes from the A module and its resources. Creating a jar and installing it in the maven repository its no problem to compile the B module but my problem its to copy the resources from A to B.
I am trying to copy the jsp and other files from A module. Following the documentation and some blogs I managed to get the target\classes\META-INF\maven\remote-resources.xml
, but when I try to copy those resources in the B module I only get the folder structure but any file inside.
A module pom
<profile>
<id>validator</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.basedir}/src/main/webapp</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
B module pom
<profile>
<id>embedded</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<configuration>
<resourceBundles>
<resourceBundle>my.group:my.artifact:${my.version}</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
</resources>
</build>
</profile>
In the output I get no errors but there are no files in the target\maven-shared-archive-resources\
only the folder structure as it is in module A.
Any idea what I am doing wrong?
Ok, I found a solution.
Looks like remote maven-remote-resources-plugin only works for resources under src/main/resources so in my case the trick was to copy /webapp/* to that folder via resources and to execute the plugin after the resources are copied I had specify <phase>process-resources</phase>
in the plugin because otherwise it was been executing before having the resources in their place.
Here is the code for the profile
<profile>
<id>share-resources</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
<!-- This is the one for webapp -->
<resource>
<directory>${project.basedir}/src/main/webapp</directory>
<targetPath>${project.build.outputDirectory}/shared-resources</targetPath>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/shared-resources/**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
To retrieve the resources in module B just did as in the documentation