2

I want to add resource from dependency jar, which resides in myjar.jar:META_INF/public-resource/myresource.sk to my webapp/WEB-INF/myfolder during mvn package goal. Does anybody can give advice, how to do this?

Mihail Zheludev
  • 166
  • 3
  • 10

1 Answers1

10

If myjar is in mvn repository, like it should be, something like

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                       <artifactItems>
                         <artifactItem>
                            <groupId>mygroupid</groupId>
                            <artifactId>myjar</artifactId>
                            <outputDirectory>src/main/webapp/WEB-INF/myfolder</outputDirectory>
                            <includes>META_INF/public-resource/myresource.sk</includes>
                          </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
 </build>
eis
  • 51,991
  • 13
  • 150
  • 199
  • 1
    Avoid extracting to the `src` folder. A dedicate directory in `target` like `${outputDirectory}/sk-resource` is more appropriate. Then add that output directory as part of the resources of the WAR by using, for example, maven-build-helper plugin – Adrian Shum Sep 02 '13 at 06:05
  • @AdrianShum agreed. Src folder was defined by OP in the question. – eis Sep 02 '13 at 06:10
  • @eis, Thanks! Good idea, but when is being built **build-helper-maven-plugin** is executing before unpacking my target resources. How to do reverse order? – Mihail Zheludev Sep 02 '13 at 07:56
  • @MihailZheludev you should actually execute the plugin *before* the package phase, not during it (which you asked on the question). So bind the unpack for example to compile phase, not to package phase. In practice, set phase to `compile` in the above config. – eis Sep 02 '13 at 08:00
  • @eis, unfortunately can't to do this with **maven-dependency-plugin + build-helper-maven-plugin**, but implemented with **maven-dependency-plugin + maven-war-plugin**. – Mihail Zheludev Sep 02 '13 at 09:18