I need editing POM at runtime. I used Dom4j for read pom and after that set some data. But i need know if exist another form for to do this. Exist a maven utilities for this?
Use the properties-maven-plugin to write specific pom properties to a file at compile time, and then read that file at run time.
Now when you edit the file in any good editor (including jEdit or Eclipse) the editor will actually download the . xsd file from the URL above and use it to guide you and validate the POM. e.g. in Eclipse, go somewhere in the POM and hit Ctrl-Space - it will bring up a list of valid elements for the current position.
mvn scm:checkin -Dincludes=pom. xml -Dmessage="Setting version, preping for release." Then you can perform your release (I recommend the maven-release-plugin), after which you can set your new version and commit it as above. The versions plugin is your friend.
Use MavenXpp3Reader
to read and MavenXpp3Writer
to write Model
objects. Simple example:
String baseDir = "/your/project/basedir/";
//Reading
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileInputStream(new File(baseDir, "/pom.xml")));
//Editing
model.setUrl("http://stackoverflow.com");
//Writing
MavenXpp3Writer writer = new MavenXpp3Writer();
writer.write(new FileOutputStream(new File(baseDir, "/pom.xml")), model);
And notice that any comment, extra white spaces or lines will be removed from the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With