2010-12-10 12 views
1

maven pom.xml을 구문 분석하려고했습니다. 나는 어느 정도 성공했다. 하지만 내 문제는 내가 기본값을 얻을 수 없다는 것입니다. 수동으로 기본값을 주입해야합니다. 예를 들어 pom.xml에 버전 번호가 지정되어 있지 않으면 부모 버전이 사용됩니다. 빌드 디렉토리가 지정되지 않으면 대상이됩니다.maven par.xml 구문 분석, maven jar 사용

이 항목을 자동으로 채우려면 어떤 클래스를 사용해야 하는지를 알아야합니다. 그 외에도 의존성 그래프를 만들어보고 싶습니다. 구문 분석에 사용하는 코드는 다음과 같습니다.

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

감사합니다.

답변

-1

도움말 : effective-pom 플러그인 목표 코드를 확인하거나 실제로 효과적인 POM 및 xml 구문 분석 결과를 덤프하는 데 사용하십시오.

관련 문제