2014-01-24 57 views
0

我正在尝试创建tar并排除roopendra 目录中的文件,但似乎不起作用。当我试图解压文件时,我收到错误gzip: stdin: not in gzip format。我的文件排除也无法正常工作。运行build.xml后,它创建了tar,但是当我试图解压缩如下。我使用Ant version 1.9.3无法使用ANT创建焦油

命令:

$ tar -xvzf projecttar.tar.gz 

四处错误:

gzip: stdin: not in gzip format 
tar: Child returned status 1 
tar: Error is not recoverable: exiting now 

的build.xml:

<?xml version="1.0"?> 
<project name="testdir" default="all_task" basedir="."> 
    <property name="src" value="src"/> 
    <property name="build" value="build"/> 
     <property name="lib" value="lib"/> 
     <property name="project.dir" value="${project}/testdir" /> 

     <target name="all_task"> 
      <antcall target="create_directory"/> 
      <antcall target="create_tar"/> 
     </target> 

     <target name="create_directory"> 
      <mkdir dir="${dist}" /> 
      <echo message=" ${dist} directory created successfully" /> 
     </target> 

     <target name="create_tar"> 
      <tar destfile="${project}/build/projecttar.tar.gz" compression="gzip" 
         basedir="${project.dir}" 
            excludes="${project.dir}/roopendra/**"/> 
     </target> 

</project> 

build命令: -

ant -buildfile build.xml -Ddist=/home/pathto/roop/projectRv/ -Dproject=/home/pathto/roop/ 

输出: -

Buildfile: /opt/apache-ant-1.9.3/build.xml 

all_task: 

create_directory: 
    [echo] /home/pathto/roop/projectRv/ directory created successfully 

create_tar: 
     [tar] Building tar: /home/pathto/roop/build/projecttar.tar.gz 

BUILD SUCCESSFUL 
Total time: 0 seconds 

我已经尝试: Ant not creating tar files

后运行

ant -v 

输出:

Apache Ant(TM) version 1.9.3 compiled on December 23 2013 
Trying the default build file: build.xml 
Buildfile: /opt/apache-ant-1.9.3/build.xml 
Detected Java version: 1.7 in: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64/jre 
Detected OS: Linux 
parsing buildfile /opt/apache-ant-1.9.3/build.xml with URI = file:/opt/apache-ant-1.9.3/build.xml 
Project base dir set to: /opt/apache-ant-1.9.3 
parsing buildfile jar:file:/opt/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/opt/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file 
Property "project" has not been set 
Build sequence for target(s) `all_task' is [all_task] 
Complete build sequence is [all_task, create_tar, create_directory, ] 

all_task: 
Project base dir set to: /opt/apache-ant-1.9.3 
    [antcall] calling target(s) [create_directory] in build file /opt/apache-ant-1.9.3/build.xml 
parsing buildfile /opt/apache-ant-1.9.3/build.xml with URI = file:/opt/apache-ant-1.9.3/build.xml 
Project base dir set to: /opt/apache-ant-1.9.3 
Override ignored for property "src" 
Override ignored for property "build" 
Override ignored for property "lib" 
Property "project" has not been set 
Override ignored for property "project.dir" 
Build sequence for target(s) `create_directory' is [create_directory] 
Complete build sequence is [create_directory, create_tar, all_task, ] 
    [antcall] Entering /opt/apache-ant-1.9.3/build.xml... 
Build sequence for target(s) `create_directory' is [create_directory] 
Complete build sequence is [create_directory, create_tar, all_task, ] 

create_directory: 
Property "dist" has not been set 
    [mkdir] Skipping /opt/apache-ant-1.9.3/${dist} because it already exists. 
Property "dist" has not been set 
    [echo] ${dist} directory created successfully 
    [antcall] Exiting /opt/apache-ant-1.9.3/build.xml. 
Project base dir set to: /opt/apache-ant-1.9.3 
    [antcall] calling target(s) [create_tar] in build file /opt/apache-ant-1.9.3/build.xml 
parsing buildfile /opt/apache-ant-1.9.3/build.xml with URI = file:/opt/apache-ant-1.9.3/build.xml 
Project base dir set to: /opt/apache-ant-1.9.3 
Override ignored for property "src" 
Override ignored for property "build" 
Override ignored for property "lib" 
Property "project" has not been set 
Override ignored for property "project.dir" 
Build sequence for target(s) `create_tar' is [create_tar] 
Complete build sequence is [create_tar, create_directory, all_task, ] 
    [antcall] Entering /opt/apache-ant-1.9.3/build.xml... 
Build sequence for target(s) `create_tar' is [create_tar] 
Complete build sequence is [create_tar, create_directory, all_task, ] 

create_tar: 
Property "project" has not been set 
Property "project" has not been set 
    [antcall] Exiting /opt/apache-ant-1.9.3/build.xml. 

BUILD FAILED 
/opt/apache-ant-1.9.3/build.xml:28: The following error occurred while executing this line: 
/opt/apache-ant-1.9.3/build.xml:42: basedir does not exist! 
    at org.apache.tools.ant.taskdefs.Tar.execute(Tar.java:249) 
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) 
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
    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 org.apache.tools.ant.Task.perform(Task.java:348) 
    at org.apache.tools.ant.Target.execute(Target.java:435) 
    at org.apache.tools.ant.Target.performTasks(Target.java:456) 
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) 
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38) 
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248) 
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440) 
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105) 
    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 org.apache.tools.ant.Task.perform(Task.java:348) 
    at org.apache.tools.ant.Target.execute(Target.java:435) 
    at org.apache.tools.ant.Target.performTasks(Target.java:456) 
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) 
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364) 
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248) 
    at org.apache.tools.ant.Main.runBuild(Main.java:851) 
    at org.apache.tools.ant.Main.startAnt(Main.java:235) 
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) 
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) 
+0

作品定皮的时候了构建适合我(project'属性中设置'dist'和'为合理值并且创建一个样本目录层次后)没有被保存下来。你确定你是在正确的目录下,并且确实在检查刚被ant创建的'.tar.gz'文件吗?当您运行上面的构建文件时,输出是什么?我还建议进一步缩小构建文件 - 在您的测试场景中不需要'dist'目标 –

+0

@Andreas:感谢您的快速响应。是dist和项目作为参数和文件创建正确提供。我还添加了有问题的构建命令和输出。 – Roopendra

+0

我已经完成了。我在问题中添加的最新输出 – Roopendra

回答

0

这里http://www.donaldsimpson.co.uk/?p=122最后,我已得到解决。文件权限使用Ant

<target name="create_tar"> 
    <tar destfile="${project}/build/projecttar.tar.gz" basedir="${project.dir}" longfile="gnu" compression="gzip"> 

     <tarfileset dir="${project}/build/" filemode="755"> 
      <include name="**/*roopendra/*.sh" /> 
     </tarfileset> 

    </tar> 
</target>