Search code examples
mavenmaven-2dependency-managementmaven-dependency-plugin

How to include resources from war to another maven project


I have a maven project , which needs to copy webapp/WEB-INF/ resources from another maven project which is packaged as a war . How do I do it ? PLease suggest


Solution

  • As Bittrance said, you should use the maven dependency plugin.

    The better way is to create project that include all your shared resources, probably a type zip, which is build up with the assembly plugin. This is the good "maven way". It's a better solution than unpacking a war.

    Then, refer it

        <dependency>
            <groupId>com.mygroup/groupId>
            <artifactId>my-dependencies</artifactId>
            <version>1.0.0</version>
            <type>zip</type>
        </dependency>
    

    Next, you use the maven dependency plugin to unpack your resources, in the directory of your choice (probably WEB-INF/ ?)

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
           <execution>
               <id>unpack-cfg-test-resources</id>
               <goals>
                    <goal>unpack-dependencies</goal>
               </goals>
               <phase>resources</phase>
                  <configuration>
                    <outputDirectory>${project.build.directory}/WEB-INF/</outputDirectory>
                                    <includeArtifacIds>my-resources</includeArtifacIds>
                    <excludeTypes>pom</excludeTypes>
                    <excludeTransitive>true</excludeTransitive>
                </configuration>
            </execution>
         </executions>
     </plugin>
    

    I'm not realy sure of this code snippet (written for another purpose), but this is an example. For more information, please follow this link : http://maven.apache.org/plugins/maven-dependency-plugin/

    If you can't shared a common-project including your files, you can unpack war including only ftl (or whatever you want), but it's not a realy clean solution ;)

    There is a lot of posts that deal with this subject : Unzip dependency in maven ... Just try with the keywords maven-dependency-plugin, unpack :)

    Hope that will help you.