Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy resources from other module to specific location ? (maven)

Tags:

maven-2

maven

I have a maven-managed project with some modules. One module contains some native codes inside "src/main/resources/native" directory. Second module packages all related modules to a WAR file.

Here comes the question : How to copy the "native/" directory (and its sub-directories) in first module to WEB-INF/native directory in the second module ?

I found a copy resources plugin , but it seems not what I want. (It copies directory inside the same module , but I want cross-module copy)

like image 421
smallufo Avatar asked Jun 02 '10 11:06

smallufo


People also ask

What is Maven remote resources plugin?

This plugin is used to retrieve JARs of resources from remote repositories, process those resources, and incorporate them into JARs you build with Maven. A very common use-case is the need to package certain resources in a consistent way across your organization.

What is Basedir in POM xml?

basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.

Can two Maven modules depend on each other?

Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.


2 Answers

This is doable with dependency:unpack (that I would bind on the prepare-package phase) and the appropriate excludes/includes . See the Unpacking specific artifacts example.

like image 72
Pascal Thivent Avatar answered Sep 27 '22 19:09

Pascal Thivent


The goal of modules in maven is to spearate them from each other. I am afraid there will be no satisfactory solution inside maven as this goes against the grain.

A solution could be to create a war archive with your resources and depend on that to build your final war.

I use for a project for example the camel-web resources by adding a dependency :

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-web</artifactId>
        <version>${camel.version}</version>
        <type>war</type>
        <scope>runtime</scope>
    </dependency>

The war resources are merged with my web resources.

like image 26
Peter Tillemans Avatar answered Sep 27 '22 20:09

Peter Tillemans