【问题标题】:Unable to create tar using ANT无法使用 ANT 创建 tar
【发布时间】:2014-01-24 09:24:16
【问题描述】:

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

命令:

$ 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>

构建命令:-

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)

【问题讨论】:

  • 为我工作(在将distproject 属性设置为合理值并创建示例目录层次结构之后)。您确定您在正确的目录中,并且您确实正在检查 ant 刚刚创建的 .tar.gz 文件吗?运行上面的构建文件时的输出是什么?我还建议进一步缩小构建文件 - 在您的测试场景中不需要 dist 目标
  • @Andreas:感谢您的快速回复。是的, dist 和 project 作为参数正确提供,并且正在创建文件。我还添加了相关的构建命令和输出。
  • 我已经做到了。我添加的最新输出有问题
  • 如果在命令行输入file /home/pathto/roop/build/projecttar.tar.gz,会输出什么?
  • 我得到输出:projecttar.tar.gz: POSIX tar archive

标签: linux ant build-process tar


【解决方案1】:

最后,我在这里找到了解决方案 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>

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 2013-05-03
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多