简体   繁体   中英

Maven resources plugin copy file

I'd like to copy eclipse.properties.ref as eclipse.properties if eclipse.properties does not exist. I'm using maven 3.2 and Java 7.

I tried the following, but not sure how to map the old file to new.

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.1</version>
  <executions>
    <execution>
      <id>copy-resources</id>
      <!-- here the phase you need -->
      <phase>test</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>/src/test/resources</outputDirectory>
        <resources>          
          <resource>
            <directory>/src/test/resources</directory>
            <includes>
              <include>eclipse.properties.ref</include>
            </includes>
            <filtering>true</filtering>
          </resource>
        </resources>              
      </configuration>            
    </execution>
  </executions>
</plugin>

You can achieve your goal using maven-antrun-plugin . It seems like copy does exactly is what you need.

<executions>
    <execution>
        <phase>generate-resources</phase>
        <goals>
            <goal>run</goal>
        </goals>
        <configuration>
            <target>
                <property 
                    name="resources"
                    value="${project.basedir}/src/test/resources" />
                <copy 
                    overwrite="false"
                    file="${resources}/eclipse.properties.ref"
                    toFile="${resources}/eclipse.properties" />
            </target>
        </configuration>
    </execution>
</executions>

NOTE

Also I'd suggest you to copy to ${project.build.testOutputDirectory} instead of ${project.basedir}/src/test/resources so it's will not hurt your version control system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM