2014-01-24 59 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>