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?
Asked
Active
Viewed 4,563 times
2
-
is myjar installed in maven repository? – eis Sep 02 '13 at 05:57
-
yes, it's installed there – Mihail Zheludev Sep 02 '13 at 07:44
1 Answers
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
-
1Avoid 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
-
-
@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