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

发布于 2024-09-25 19:58:57 字数 1086 浏览 10 评论 0 原文

我目前正在这样做:

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

我现有的安装程序 JAR 已更新,以包含从应用程序 JAR 中提取的所需文件。

到目前为止,一切都很好。

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

当前:

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

我想要的:

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

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

除了解压缩整个内容复制文件然后再次压缩之外,还有其他方法可以做到这一点吗?


编辑:

链接到之前的相关问题: ant 任务从 jar 中删除文件

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.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼泪都笑了 2024-10-02 19:58:57

您可以使用 fullpath 属性:

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

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

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

You can use the fullpath attribute:

<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 prefix attribute, e.g.:

<zipfileset src="${pwd}/dist/app.jar"
    includes="**/*.png" prefix="blah/img"/>
安人多梦 2024-10-02 19:58:57

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

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

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

<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>
淡淡離愁欲言轉身 2024-10-02 19:58:57

您可能应该查看 zipgroupfileset ,如所解释的 此处

You should probably look into zipgroupfileset as explained here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文