0

We have stuck is a scenario were we need to copy some property file to class path, when the file does not exists.

We are using maven to build and maven ant task to copy file.

We have used any copy task like below:

<copy file="src/systemConfig.properties" tofile="src/test/resources/systemConfig.properties" />

This copy task will copy the src file to dest when file does not exits or dest file is older than src file.

However i need to do the copy if and only if file does not exist.

Could you please help me?

Prasobh.Kollattu
  • 1,665
  • 1
  • 22
  • 32
  • 1
    Are you sure you are using Maven correctly? Before the Test phase all test Resources are copied to the build directories `test-classes` directory, so even if you would change the file contents, on the next Build they are restored. So why not put the file from `src` directly in `src/test/resources`? messing with the source directory at build time is a bad idea, Thats what the build directory is for. – Blank Chisui Feb 27 '14 at 11:04
  • I am using maven-antrun-plugin version 1.7 and the follwoing execution code copy-system-config process-test-sources run – Prasobh.Kollattu Feb 27 '14 at 11:44
  • You didn't understand the previous comment which exactly explained how to use Maven which already does what you need. So no need for anttask. Apart from that if you have integration tests you should use maven-failsafe-plugin and a different way of going but copying files via ant taks is simply the wrong way. – khmarbaise Feb 27 '14 at 11:50
  • khmarbaise and Blank Chisui , Thanks for your comments. the systemConfig.prop in test/resourec will be modified by the user according to their environment. So we are planning to not update sysConf if all ready present in test/resource. Any new config change, user should manully update in syscon in test/resource – Prasobh.Kollattu Feb 27 '14 at 12:12

1 Answers1

0

Use this:

<if>
    <available file="src/test/resources/systemConfig.properties"/>
    <then>
       <copy file="src/systemConfig.properties" tofile="src/test/resources/systemConfig.properties" />
    </then>

</if>

Answer is already here on stackoverflow

Community
  • 1
  • 1
Rahul
  • 3,479
  • 3
  • 16
  • 28
  • Rahul Thanks for the response.With the code you suggested the file copying is not working.. we are using maven-antrun-plugin version 1.7 – Prasobh.Kollattu Feb 27 '14 at 11:13
  • @Prasobh.K copy line is of you as used by you. Which file do you want to check present or not should ne in available tag. – Rahul Feb 27 '14 at 11:21
  • i want to check, tofile ie.destination file..if destination file does not exists i need to copy source to destination. – Prasobh.Kollattu Feb 27 '14 at 11:33