POM_XPATH_INJECT(7)

πŸ’… POM_XPATH_INJECT πŸ’…

okay bestie, welcome to pom_xpath_inject, a page straight out of the Java Packages Tools manual (section 7, if you're keeping track). sit down, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

pom_xpath_inject β€” inject code into XML file 🧚


🌸 SYNOPSIS 🌸

%pom_xpath_inject XPath XML-code [XML-file-location]...

πŸ¦‹ DESCRIPTION πŸ¦‹

so what this macro does is patch a specified XML file by appending the code you give it as children of all the XML nodes that your XPath expression describes. not some of them. all of them. periodt. πŸ’…

XPath is an expression describing a set of XML nodes in the XML file where the child code is gonna get appended. it has to be a properly formatted XPath 1.0 expression, exactly like the one described at http://www.w3.org/TR/xpath/. no improvising, bestie, the spec is the spec.

Maven POM files use the specific XML namespace http://maven.apache.org/POM/4.0.0 as their default. that namespace needs to be explicitly specified in XPath expressions by prefixing every node name with pom: (like pom:modelVersion, iykyk).

and it's not just POMs β€” many other XML formats also use namespaces, and you have to explicitly specify those too. the way this works: the script uses the namespace prefix names from the xmlns declarations in the document's root element. so if the document starts with <root xmlns:my="myurl.com"> you'd select the root node with the XPath expression /my:root. and if the document specifies a default namespace (like xmlns="myurl.com"), use the prefix named default to access elements in that namespace. iconic behavior honestly.

now, XML location β€” it can be either a full path to the XML, or a path to the directory containing pom.xml or ivy.xml. if you don't give an XML location at all, then pom.xml or ivy.xml from the current working directory gets used. and when both pom.xml and ivy.xml are present? pom.xml is the one that gets processed, no debate. you can also specify more file locations if you're feeling ambitious. πŸ”₯


πŸŽ€ EXAMPLES πŸŽ€

okay let's see it in action:

  • %pom_xpath_inject pom:project "<packaging>war</packaging>" β€” this call sets the packaging of the POM in the current working directory to war. slay. πŸ‘‘
  • %pom_xpath inject configurations '<conf name="test"/>' β€” this adds a new configuration to the Ivy file in the current working directory. πŸ’–

πŸ‘‘ AUTHOR πŸ‘‘

Written by Mikolaj Izdebski.


😭 REPORTING BUGS 😭

found a bug? no gatekeeping β€” bugs should be reported through the Java Packages Tools issue tracker at Github: https://github.com/fedora-java/javapackages/issues. go tell them, bestie, they wanna know. 🫢


🌈 SEE ALSO 🌈


and that's the whole page, bestie! this edition is brought to you by JAVAPACKAGES, dated 2025-09-19 β€” so if you're reading this in the future, hi, hope the XPath still slaps. bye, love you, go inject some XML πŸ’œβœ¨

πŸ“¦ where this page comes from