2013-09-05 4 views
19

두 프로필이 pom.xml에 있고 첫 번째 프로필 실행 중에 대상 리소스 디렉토리에 추가 한 리소스 파일이 하나 있습니다 (${project.build.outputDirectory}/resources). 내가해야 할 일은 두 번째 프로필을 실행하는 동안 해당 리소스 파일을 제거하는 것입니다. 대상 디렉토리에서 기존 파일을 제거하거나 삭제할 수있는 방법이 있습니까?pom 파일을 사용하여 대상 디렉토리에서 리소스 파일 제거 또는 삭제

답변

11

mvn cleantarget 디렉토리 (및 그에 포함 된 모든 파일)를 제거합니다. 당신의 target 디렉토리에서의 조합을 특정 파일을 제거하려면 다음

  • excludeDefaultDirectories 전체 디렉토리를 삭제을 중지하고, 무엇을 삭제

  • filesets은 말할

심판 : 나는 매튜의 observatio에 동의 http://maven.apache.org/plugins/maven-clean-plugin/clean-mojo.html

21

ns이지만 원래 포스터가 프로파일의 (정상적인) "실행"중에 clean의 실행을 자동화하는 방법을 묻고 있다는 인상을 받았습니다.

Maven Clean Plugin에 대해 plugin execution을 정의 할 수 있습니다. 일반적으로 clean에 바인딩되지만 플러그인 실행을 정의하면 clean:clean (플러그인의 clean 목표)을 lifecycle phase 중 원하는 것으로 바인딩 할 수 있습니다. Maven Clean Plugin의 문서에는 이것을 수행하는 방법에 대한 an example이 있습니다. 설명서에는 an example의 추가 파일이 삭제됩니다. 두 모양을 병합했습니다.

<plugin> 
    <artifactId>maven-clean-plugin</artifactId> 
    <version>2.5</version> 
    <executions> 
     <execution> 
     <id>auto-clean</id> 
     <phase>initialize</phase> 
     <goals> 
      <goal>clean</goal> 
     </goals> 
     <configuration> 
     <filesets> 
      <fileset> 
       <directory>some/relative/path</directory> 
      </fileset> 
      </filesets> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
22

해결책이 있습니다 .. !! 참조

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-antrun-plugin</artifactId> 
<version>1.7</version> 
<executions> 
    <execution> 
     <phase>test</phase> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     <configuration> 
      <tasks> 
       <delete> 
        <fileset dir="${project.build.outputDirectory}/resources" includes="*.xml" /> 
       </delete> 
      </tasks> 
     </configuration> 
    </execution> 
</executions> 
</plugin> 

- 위의 답변에 http://maven.apache.org/guides/mini/guide-building-for-different-environments.html

+0

일반적으로, 메이븐에, 당신은 그냥 개미, 그루비 같은 위해 (이 플러그인을 그것을 코딩을 통해, 선언적 솔루션을 선호하는 것 : 당신이 here

가 참조하는 수행 할 수있는 개미 작업

목록 , 등) 할 수 있습니다. –

2

감사합니다. 마지막으로 내가 좋아하는 일에 온 : 당신은 J UST 대상 폴더에일부 디렉토리를 삭제하려면

,이 같은 일부 구조를 만들어야합니다. 예를 들어
이 폴더의 바로 모든 내용을 삭제 :

  • 대상/전체 대상 폴더를 삭제 하다며 N 허용
  • 발전기 외부 apklibs

excludeDefaultDirectories 압축을 풉니 다.
린트 분석 전에 대상 폴더를 정리하는 데 사용했습니다.Apache Maven AntRun Plugin 1.8

 <plugin> 
      <artifactId>maven-clean-plugin</artifactId> 
      <version>2.6</version> 
      <executions> 
       <execution> 
        <id>Deleting all unnecessary files before lint analysis</id> 
        <phase>verify</phase> 
        <goals> 
         <goal>clean</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <excludeDefaultDirectories>true</excludeDefaultDirectories> 
       <filesets> 
        <fileset> 
         <directory>target/unpack</directory> 
         <followSymlinks>false</followSymlinks> 
         <excludes> 
          <exclude>*</exclude> 
         </excludes> 
        </fileset> 
        <fileset> 
         <directory>gen-external-apklibs</directory> 
         <followSymlinks>false</followSymlinks> 
         <excludes> 
          <exclude>*</exclude> 
         </excludes> 
        </fileset> 
       </filesets> 
       <verbose>true</verbose> 
      </configuration> 
     </plugin> 
4

솔루션 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.8</version> 
    <executions> 
    <execution> 
     <phase>initialize</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
     <configuration> 
     <target> 
      <delete 
      dir="${project.build.outputDirectory}/resources" 
      includeemptydirs="true"/> 
     </target> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 
1

내가 출력 디렉토리에서 삭제 된 파일의 몇 필요는, 다음은 나를 위해 잘 일했다.

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.8</version> 
    <executions> 
     <execution> 
      <phase>compile</phase> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      <configuration> 
       <tasks> 
        <delete file="${project.build.outputDirectory}/appContextLocal.xml" /> 
        <delete 
         file="${project.build.outputDirectory}/appContextServer.xml" /> 
       </tasks> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

은 또한 당신이 어떤 개미 명령을 실행 이제까지 당신이 <tasks> .... </tasks> 사이에 필요한 작업 무엇을 교체하고 작동 할 수 있다는 생각. http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

관련 문제