2017-03-05 8 views
2

this Stack Overflow question에 제안 된 솔루션을 내 Maven 프로젝트에 추가했습니다. 내가 제안한 제안 된 솔루션의 유일한 차이점은 <tasks /><target />으로 대체하는 것입니다 (발생한 문제는이 중 하나와 함께 나타남).maven-antrun-plugin이 실행을 건너 뜁니다.

모든 것이 테스트면에서 뛰어납니다. 테스트를 실행할 때 올바른 (test-persistence.xml) 지속성 파일이 사용되고 있습니다. 그러나 내가 깔끔한 설치를하거나 내 IDE (Netbeans 8.2)에서 실행을하면 첫 번째 대상 (copy-test-persistence) 만 실행됩니다. 두 번째 실행은 테스트 후에 입력되지만 (아래 빌드 출력 참조) 대상은 실행되지 않습니다. 모든 clean install 이후에 내가 무엇을하는지, 그리고 서버에서 앱을 실행할 때 test-persistence.xml의 내용이 persistence.xml 파일에 있다는 것입니다. 올바른 콘텐츠는 첫 번째 대상에 생성 된 persistence.xml.proper에 남아 있습니다.

--- maven-antrun-plugin:1.8:run (copy-test-persistence) @ RimmaNew --- 
Executing tasks 

main: 
    [copy] Copying 1 file to /my-project-home/target/classes/META-INF 
    [copy] Copying 1 file to /my-project-home/target/classes/META-INF 
Executed tasks 

... 

--- maven-antrun-plugin:1.8:run (restore-persistence) @ RimmaNew --- 
Executing tasks 

main: 
Executed tasks 

restore-persistence에는 0 개의 작업이 실행됩니다. 당신이 나에게 나는이 주위에 내 머리를 얻을 수있는 힌트를 줄 수 있다면 그것은 감사하겠습니다

<?xml version="1.0" encoding="UTF-8" ?> 
<project name="maven-antrun-" default="main" > 
<target name="main"> 
    <copy file="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml.proper" tofile="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml"/> 
</target> 
</project> 

: 생성 된 /target/antrun 폴더에 이상하게도 건너 뛴 작업을 포함하는 build-main.xml 파일이있다. 내가 게시하고 공통으로 내 현재 pom.xml :

문제는 개미의 copy 작업 작업 방법과 함께 할 수있어 한
<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.8</version> 
    <executions> 
     <execution> 
      <id>copy-test-persistence</id> 
      <phase>process-test-resources</phase> 
      <configuration> 
       <target> 
        <!--backup the "proper" persistence.xml--> 
        <copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper" /> 
        <!--replace the "proper" persistence.xml with the "test" version--> 
        <copy file="${project.build.testOutputDirectory}/META-INF/test-persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" /> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>restore-persistence</id> 
      <phase>prepare-package</phase> 
      <configuration> 
       <target> 
        <!--restore the "proper" persistence.xml--> 
        <copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" /> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

답변

2

: 소스 파일이 최신 버전 인 경우

기본적으로

파일 만 복사 대상 파일보다 크거나 대상 파일이없는 경우

여기가 문제입니다. Ant는 대상 파일이 이미 존재하며 새로운 파일이 아니라는 것을 감지합니다. "신형"을 결정하는 정밀도가 있으며 기본적으로 DOS 시스템에서는 1 초 또는 2 초입니다. 따라서 빌드하는 동안 persistence.xml이 Maven에 의해 빌드 디렉토리에 복사되고 마지막 수정 날짜가 변경되며 (Resources Plugin doesn't keep it), 사용자 자신의 복사본은 몇 밀리 초 후에 나타납니다. 따라서 복사 된 persistence.xml.proper은 기본 세밀도 동안 모든 것이 발생하기 때문에 결코 최신이 아닙니다.

당신은

<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" 
     tofile="${project.build.outputDirectory}/META-INF/persistence.xml" 
     overwrite="true"/> 

trueoverwrite 매개 변수를 설정하여 사본을 강제 할 수 또는 당신은 아마 어쨌든 .proper 파일을 유지할 필요가 없기 때문에 당신은 대신 move 작업을 사용할 수 있습니다

<move file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" 
     tofile="${project.build.outputDirectory}/META-INF/persistence.xml" /> 
+0

화려한 - 내 문제가 해결되었습니다. 고마워요! – vasigorc