依赖
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.0</version>
</dependency>
示例代码:
MavenXpp3Reader reader = new MavenXpp3Reader();
String myPom = rootPath + File.separator + "pom.xml";
Model model = null;
try {
model = reader.read(new FileReader(myPom));
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
String artifactId = model.getArtifactId();
System.out.println(artifactId);