'"can't write to read-only destination file" with ANT

Ant build fails with below error about "can't write to read-only destination file". Is this an issue with Windows permissions error or something with Ant?

BUILD FAILED
E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\build.xml:32: The following error occurred while executing this line:
E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\build.xml:116: Failed to copy E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\tealeaf-w3c-dev.js to E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\web\tealeaf-w3c-dev.js due to can't write to read-only destination file E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\web\tealeaf-w3c-dev.js
ant


Solution 1:[1]

Prior to ANT 1.8.2, it was able to copy files to read-only destinations. However, after 1.8.2 the behavior has changed.

So, in this case, you can force the copy task to make it work:

<copy force="true" todir="${web.home}/WEB-INF/web"> 
   <fileset dir="${web.home}/WEB-INF"> 
     <include name="*/.*"/> </fileset> 
</copy> 

Solution 2:[2]

In my case i had the problem with this configuration in my pom.xml, which throws that exception (can't write to read-only destination file) when i run mvn -Dmaven.test.skip=true clean package:


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <goals>
          <goal>run</goal>
        </goals>
        <phase>generate-sources</phase>
        <configuration>
          <target>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.version=${project.version}${line.separator}"/>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.build=${buildNumber}${line.separator}" append="true"/>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.timestamp=${timestamp}" append="true"/>
          </target>
        </configuration>
      </execution>
    </executions>
</plugin>

The key was to put force="true" in each "echo" tag.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ANIL
Solution 2 Vikcen