虽然文件存在,但无法在ant.copy中找到要复制的文件

时间:2015-03-03 17:02:47

标签: unix ant groovy

我在一个时髦的脚本中调用ant.copy:

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

虽然该文件存在于路径下,但调用失败,但下面有例外。

在Windows上启动的相同代码有效。当使用java jdk1.7.0_51在Unix上启动时,它失败了。

Unix上的机器详细信息:

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

有什么想法吗?

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)

由于

1 个答案:

答案 0 :(得分:1)

copy任务在运行以下代码段时失败(来自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);
            }
        }
    }
}

在消息字符串中,文件名/data/apps/packages/temp/jconn3-6.05_26312.jar中还有一个空格。

这也可以使用以下内容复制:

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

file.exists()在Windows上返回true(自动修剪),但在SunOS上返回false。