How to include resources from the war in another maven project

I have a maven project that needs to copy webapp / WEB-INF / resources from another maven project that is packaged like a war. How can I do it? PLease offers

+1
source share
3 answers

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

It’s best to create a project that includes all of your shared resources, possibly a zip type that is created using the build plugin. This is a good "way for two." This is a better solution than unpacking a war.

Then indicate

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

Then you use the maven dependency plugin to unpack the resources in the directory of your choice (possibly 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 quite sure about this piece of code (written for another purpose), but this is an example. For more information, follow this link: http://maven.apache.org/plugins/maven-dependency-plugin/

If you cannot use a common project, including your files, you can unpack the war, including only ftl (or anything), but this is not a very clean solution;)

There are many posts devoted to this topic: Cancel dependency in maven ... Try using the keywords maven-dependency-plugin, unpack :)

Hope this helps.

0
source

I see some alternatives:

  • Use external links in your version control system to point all repositories to the same files.
  • The Maven Dependency module can copy and decompress project dependencies. From there, you can use the Maven Assembly (or Ant target) plugin to include parts of this dependency in your own installation.
  • At least for FTL files, perhaps you can pack them into a separate Jar file and then load them as resources through the class loader.

If resources are filtered, you may run into the problem of solution 1 if you want a filtered version and 2, 3 if you want the original version.

Hope this helps.

+1
source

(It is assumed that your dependent project is java (jar) and not another web application, if it is webapp, I think the solution is similar).

I suggest a (slightly) different approach:
Instead of reading resources from the war, add this to your military pump to create a can in the artifact, as well as the war:

 <!-- maven war plugin config --> <plugin> <groupId>org.apache.maven.plugins</groupId> <configuration> ... <attachClasses>true</attachClasses> <classesClassifier>some-string</classesClassifier> </configuration> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> </plugin> ... <resources> <!-- This is for inclusion in the jar, so dependent module can load it --> <resource> <targetPath>some-path</targetPath> <directory>src/main/webapp/path...</directory> <includes> <include>your-resource</include> </includes> </resource> </resources> 

And this is for your consuming pump, so the generated jar will be loaded:

 <dependency> <groupId>com.company</groupId> <artifactId>...</artifactId> <classifier>some-string</classifier> </dependency> 

Then you can load resources in the usual way ( getResourceAsStream("some-path/your-resource") )

0
source

All Articles