2

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?

Gerardo
  • 81
  • 1
  • 9
  • Can you elaborate a little bit more, cause copying resources like jsp's sounds wrong to me. Apart from that why are you using an old version of [maven-remote-resources-plugin](http://maven.apache.org/plugins/maven-remote-resources-plugin/) currently 1.5. – khmarbaise Jan 12 '15 at 16:17
  • I tried with different versions of the plugin and it doesn't change anything. Elaborate a bit more is kind of difficult, there's not to much to say, the module B is an extension of module A and what we want is that any change in module A will be copied to module B automatically – Gerardo Jan 13 '15 at 08:26

1 Answers1

2

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

Gerardo
  • 81
  • 1
  • 9
  • Although this did not work for me right away it pointed me to the right direction, hence +1. For others facing the same problem this thread may be helpful, too: http://stackoverflow.com/questions/30669013/using-the-maven-remote-resources-plugin-and-specifying-the-resourcesdirectory – philonous Jun 27 '16 at 08:58