1

私はmaven pom.xmlを解析しようとしています。ある程度成功しました。しかし、私の問題は、デフォルト値を取得できないことです。デフォルト値を手動で挿入する必要があります。たとえば、バージョン番号が pom.xml で指定されていない場合、親バージョンが使用されることは明らかです。ビルド ディレクトリが指定されていない場合は、それがターゲットになります。

これらのものを自動的に設定するには、どのクラスを使用すればよいかを知る必要があります。それとは別に、依存関係グラフを作成したいと思います。解析に使用しているコードは

        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();
        }
    }

ありがとう。

4

1 に答える 1

-1

help:effective-pomプラグイン ゴールのコードを確認するか、実際にそれを使用して有効な POM をダンプし、結果を xml 解析します。

于 2012-02-04T12:51:44.193 に答える