springboot项目中获取pom中的属性

依赖

<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);
原文地址:https://www.cnblogs.com/qds1401744017/p/14751296.html