Rima
Rima

Reputation: 51

Could not find file to copy in ant.copy although file exists

I am calling ant.copy in a groovy script:

ant.copy(file:jdbcDriverPath, toFile:destJDBCJarFile,overwrite:true)

The call is failing with the exception below, although the file exists under the path.

The same code launched on Windows works. When launched on Unix with java jdk1.7.0_51, it is failing.

Machine details on Unix:

$ uname -a
SunOS 5.10 Generic_142910-17 i86pc i386 i86pc
$ isainfo -kv
64-bit amd64 kernel modules

Any ideas?

Exception in thread "main" : Warning: Could not find file /data/apps/packages/temp/jconn3-6.05_26312.jar  to copy.
        at org.apache.tools.ant.taskdefs.Copy.copySingleFile(Copy.java:639)
        at org.apache.tools.ant.taskdefs.Copy.execute(Copy.java:455)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at groovy.util.AntBuilder.performTask(AntBuilder.java:250)
        at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:212)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
        at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:166)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)

Thanks

Upvotes: 1

Views: 937

Answers (1)

M A
M A

Reputation: 72854

The copy task is failing while running the below snippet (from the source of Ant 1.9.4):

private void copySingleFile() {
    // deal with the single file
    if (file != null) {
        if (file.exists()) {
            if (destFile == null) {
                destFile = new File(destDir, file.getName());
            }
            if (forceOverwrite || !destFile.exists()
                || (file.lastModified() - granularity
                    > destFile.lastModified())) {
                fileCopyMap.put(file.getAbsolutePath(),
                                new String[] {destFile.getAbsolutePath()});
            } else {
                log(file + " omitted as " + destFile
                    + " is up to date.", Project.MSG_VERBOSE);
            }
        } else {
            String message = "Warning: Could not find file "
                + file.getAbsolutePath() + " to copy.";
            if (!failonerror) {
                if (!quiet) {
                  log(message, Project.MSG_ERR);
                }
            } else {
                throw new BuildException(message);
            }
        }
    }
}

From the message string, there is an additional space in the filename /data/apps/packages/temp/jconn3-6.05_26312.jar.

This can also be reproduced using the following:

java.io.File file = new java.io.File("some_file_that_exists ");
System.out.println(file.exists());  // true on Windows, false on SunOS

The file.exists() returns true on Windows (automatically trimmed), but false on SunOS.

Upvotes: 1

Related Questions