Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get MavenProject from just the POM.xml - pom parser?

Is it possible to get an instance of org.apache.maven.project.MavenProject or some other object form of the POM from just the pom.xml file?

Thanks in advance.

like image 830
javamonkey79 Avatar asked Dec 07 '10 20:12

javamonkey79


People also ask

How do I get property from POM xml?

In maven pom. xml , a property is accessed by using ${property_name} . You can define your custom properties in Maven.

How do you find the value of pom files?

The plugin is part of the Maven Super Pom and executed during the process-resources phase of the Jar Default Lifecyle. The only thing you have to do is to active filtering. How you make this property then available to your Java application is up to you - reading it from the classpath would work.

What is parent tag in POM xml?

As the name suggests, we can point out a parent pom.xml file for the current pom.xml file. Doing so, dependencies, properties, constants and many more defined at the parent pom.xml file also get merged with the current pom.xml (child pom.xml) file.

What is Modelversion in POM xml?

model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0. 0 just indicated that it is compatible Maven 3.


1 Answers

yes you can . This is the code. You need maven-model-3.0.4.jar and plexus-utils-2.0.6.jar and maven-core-3.0.4.jar

Model model = null;
FileReader reader = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
    reader = new FileReader(pomfile);
    model = mavenreader.read(reader);
    model.setPomFile(pomfile);
}catch(Exception ex){}
MavenProject project = new MavenProject(model);
like image 115
rxx Avatar answered Oct 20 '22 01:10

rxx