user984200
user984200

Reputation: 293

Maven replace token with content of a whole file

I want to insert the content of a file into an xml-file (using XPath or a replacer token). This should happen during the build process using maven.

My first try was to use the maven ant task plugin and the xmltask task of ant.

<xmltask source="sourceFile.xml" dest="destinationFile.xml">
  <replace path="//L7p:MapValue[2]/L7p:Mappings" withfile="xmlFileToInsert.xml" />
</xmltask>

That worked fine for a while, but now i want to insert not valid xml. This xml will be made valid in future steps - but its really required to insert invalid xml here. AFAIK, this does not work with the xmltask of ant. If you know a way to disable the validation, it would also help.

Now, I'm searching for nearly the same xmltask can do in combination with maven and ant but without the validation of xml.

What do you guys think is the best way to do this with maven?

Thanks for your opinion and help.

Upvotes: 0

Views: 1091

Answers (1)

JP Moresmau
JP Moresmau

Reputation: 7403

If you're already using Ant, just use the Ant replace task (https://ant.apache.org/manual/Tasks/replace.html). It replaces text by another in any file, so it doesn't care if it's not valid XML. Read the value to use as a replacement from your file, and have a marker token in your original file. You could still first use xmltask to insert the marker token via XPath to give valid XML, then do the textual replacement via replace.

Upvotes: 1

Related Questions