Nicola Ben
Nicola Ben

Reputation: 11317

Maven plugin: copy a file content into another file

I am looking for the appropriate plugin to copy a file content into another file.

My resource.xml has content like this:

<class>my.path.ResourceA</class>
<class>my.path.ResourceB</class>
<class>my.path.ResourceC</class>

and must be copied to destination.xml at the place of ${content}:

<aaa>some info</aaa>
${content}

What the proper maven plugin to do that task, please? Thank you in advance. Nic

Upvotes: 0

Views: 1087

Answers (2)

burriad
burriad

Reputation: 19

The answer from Baptiste does not work with the antrun plugin, as the properties from the LoadFile task are Ant properties are not accessible in Maven for filtering.

Instead, one can use the readfiles-maven-plugin, which you can find here: https://github.com/chonton/readfiles-maven-plugin

Upvotes: 0

Baptiste Mathus
Baptiste Mathus

Reputation: 908

In general with Maven, you must first thinkg WHAT you want to do. Might seem weird at first sight, but as Maven is an opinionated build tool, it will generally be not simple to do weird/workaround things ;-).

Here, you would need two things:

  1. load that file into a "content" property (before resource filtering starts by binding to an early phase, obviously, see the next point)
  2. just activate resource filtering and be done

Unfortunately, there's no well-known/standard plugin for the (1) able to load a file inside a property.

A possible way, before rewriting it through a dedicated plugin or so, would be by using antrun-maven-plugin (through LoadFile task?) or gmaven plugin to load that file into a property (during the initialize phase, for example, so that it happens before process-resources, see the documentation about lifecycle.)

Then, for (2), you simply have to activate filtering (see the standard documentation of the maven-resources-plugin).

Upvotes: 1

Related Questions