开发者

Parsing maven pom.xml, using maven jar

I have been trying to parse maven pom.xml. I was successful to an extent. But my problem is I cannot get the default values. I have to manually inject the default values. For example, if version number is not specified in pom.xml, then it is obvious that parent version will be used. If build directory is not specified then it will be target.

I need to know, which classes should I use to get these things populated automatically. Apart from that I would like to have dependency graph built for me. The code I am using to parse is

        Model model = null;
    FileReader reader = null;
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    try {
        reader = new FileReader(pomfile);
        model = mavenreader.read(reader);
        model.setPomFile(pomfile);

        if (model.getBuild() != null) {
            // location of output directory basically target
            if (model.getBuild().getDirectory() == null) {
            //set the build directory

            } // location of compiled classes
            if (model.getBuild().getOutputDirectory() == null) {
                      // set the classes directory
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException("pom file not found " + pomfile);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("pom file is not accessible " + pomfile);
    } catch (XmlPullParserException e) {
        e.printStackTrace();
        throw new RuntimeException("unable to parse pom " + pomfile);
    } catch (NullPointerException nullPointerException)
        System.out.println("Exception setting build 开发者_如何转开发dir "+model.getPackaging());

    } finally {
        if (reader != null) {
            reader.close();
        }
    }

Thanks.


Look at the code for the help:effective-pom plugin goal, or actually use it to dump the effective POM and xml-parse the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜