java ant : jar 和 zipfileset - 将文件从一个 JAR 复制到另一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3837073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:36:58  来源:igfitidea点击:

ant : jar and zipfileset - copy files from one JAR into another

javaantbuildjarzip

提问by bguiz

I am currently doing this:

我目前正在这样做:

<jar update="yes"
     jarfile="${pwd}/dist/${release}_installer.jar">
   <zipfileset src="${pwd}/dist/app.jar" includes="com/izforge/izpack/panels/**"/>
   <zipfileset src="${pwd}/dist/app.jar" includes="com/xyz/img/logo.png"/>
</jar>

My existing installer JAR gets updated to include the files as needed, extracted from the app JAR.

我现有的安装程序 JAR 得到更新,以根据需要包含从应用程序 JAR 中提取的文件。

So far, so good.

到现在为止还挺好。

However, I want to modify the behaviour such that the path of the image file is different than what is being copied from:

但是,我想修改行为,使图像文件的路径与从中复制的路径不同:

Currently:

目前:

com/izforge/izpack/panels/MyIzPanel.class
com/xyz/img/logo.png

What I want:

我想要的是:

com/izforge/izpack/panels/MyIzPanel.class
blah/img/logo.png

So I need to copy the files, but use <zipfileset>and <jar>in such a way that I can modify the directory structure.

所以我需要复制文件,但使用<zipfileset><jar>的方式可以修改目录结构。

Is there a way to do this, apart from unzipping the entire contents copying file and then zipping it back up again?

除了解压缩整个内容复制文件然后再次压缩它之外,有没有办法做到这一点?



EDIT:

编辑:

Link to earlier related question: ant task to remove files from a jar

链接到较早的相关问题:ant task to remove files from a jar

回答by Grodriguez

You can use the fullpathattribute:

您可以使用该fullpath属性:

<zipfileset src="${pwd}/dist/app.jar"
    includes="com/xyz/img/logo.png" fullpath="blah/img/logo.img"/>

If you need to copy several files you may want to have a look at the prefixattribute, e.g.:

如果您需要复制多个文件,您可能需要查看prefix属性,例如:

<zipfileset src="${pwd}/dist/app.jar"
    includes="**/*.png" prefix="blah/img"/>

回答by Hachmaninow

In order to modify the directory structure within the archive on the fly you can use the task in combination with <mappedresources>, eg:

为了动态修改存档中的目录结构,您可以将任务与<mappedresources>结合使用,例如:

<jar file="target.jar" update="true">
  <mappedresources>
    <zipfileset src="source.jar">
      <include name="com/xyz/img/*.png"/>
    </zipfileset>
    <mapper type="glob" from="com/xyz/img/*.png" to="bla/img/*.png" />
  </mappedresources>
</jar>

回答by Jarek Przygódzki

You should probably look into zipgroupfilesetas explained here.

您可能应该按照此处的说明查看zipgroupfileset