使用 Jar Jar 链接排除空目录

发布于 2024-12-20 16:12:15 字数 1175 浏览 2 评论 0原文

我正在使用 Jar Jar 链接 中的 Ant 任务来嵌入来自第 3 方 jar 文件的类(objenesis) 在我的可分发 jar 文件 (example.jar) 中。 Jar Jar 会将原始包 (org.objenesis) 中的类转换为我选择的类之一。

它可以工作,但会在可分发的 jar 中留下空目录。

这是一个简化的 build.xml:

<target name="jar" depends="compile">
    <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"
        classpath="lib/jarjar-1.1.jar"/>

    <jarjar jarfile="dist/example.jar" excludes="org.objenesis.**">
        <fileset dir="build/classes/main"/>
        <zipfileset src="lib/objenesis-1.2.jar"/>
        <rule pattern="org.objenesis.**" result="org.thirdparty.@1"/>
    </jarjar>
</target>   

example.jar 的内容示例包括(如预期):

org/thirdparty/Objenesis.class
org/thirdparty/ObjenesisBase.class

但也包括这些空目录(不需要):

org/objenesis/
org/objenesis/instantiator/
org/objenesis/instantiator/basic/

我的问题:如何排除这些空目录?

我尝试了“zap”选项(文档中列出),但没有不工作。

I am using an Ant task from Jar Jar Links to embed classes from a 3rd-party jar file (objenesis) in my distributable jar file (example.jar). Jar Jar will translate classes from the original package (org.objenesis) to one of my choosing.

It works but it leaves empty directories in the distributable jar.

Here is a simplified build.xml:

<target name="jar" depends="compile">
    <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"
        classpath="lib/jarjar-1.1.jar"/>

    <jarjar jarfile="dist/example.jar" excludes="org.objenesis.**">
        <fileset dir="build/classes/main"/>
        <zipfileset src="lib/objenesis-1.2.jar"/>
        <rule pattern="org.objenesis.**" result="org.thirdparty.@1"/>
    </jarjar>
</target>   

A sample of contents of the example.jar includes (as expected):

org/thirdparty/Objenesis.class
org/thirdparty/ObjenesisBase.class

but also these empty directories (undesirable):

org/objenesis/
org/objenesis/instantiator/
org/objenesis/instantiator/basic/

My question: how to I exclude these empty directories?

I tried the "zap" option (listed in the doc), but that didn't work.

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

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

发布评论

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

评论(1

淡淡绿茶香 2024-12-27 16:12:16

这似乎是 Jar Jar 中的一个已知问题,已在其问题跟踪器中列出:http://code.google.com/p/jarjar/issues/detail?q=empty&id=32

鉴于此问题是在大约三年前提出的,而且似乎尚未得到解决任何牵引力,我假设您的选择是提供修复程序,或者解决它。

利用 Ant 对删除副本上的空目录的支持,解决此问题的示例 Ant 目标如下:


    
    
        />
        <规则模式=“com.example.dependency.**”结果=“com.example.my-app.jarjar.com.example.dependency.@1”/>
    
    />
    <解压 src="${location.dist.binaries}/my-app.jar" dest="${location.dist.binaries}/exploded/my-app.jar"/>
    <复制 includeemptydirs="false" todir="${location.dist.binaries}/unpolluted/my-app.jar">
        />
    
    
        ;
    

虽然有点蹩脚,但它达到了你想要的。

This appears to be a known issue in Jar Jar, listed in their issue tracker: http://code.google.com/p/jarjar/issues/detail?q=empty&id=32

Given that this was raised almost three years ago and doesn't appear to have got any traction, I suppose your options are to contribute a fix, or to work around it.

An example Ant target to work around it, taking advantage of Ant's support for removing empty directories on copy, would be:

<target name="unpolluted-jarjar" description="JarJars without empty directories">
    <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${location.lib}/build/jarjar-1.2.jar"/>
    <jarjar basedir="${location.classes}" destfile="${location.dist.binaries}/my-app.jar">
        <zipfileset src="${location.lib}/shipped/dependency.jar"/>
        <rule pattern="com.example.dependency.**" result="com.example.my-app.jarjar.com.example.dependency.@1"/>
    </jarjar>
    <mkdir dir="${location.dist.binaries}/exploded"/>
    <unzip src="${location.dist.binaries}/my-app.jar" dest="${location.dist.binaries}/exploded/my-app.jar"/>
    <copy includeemptydirs="false" todir="${location.dist.binaries}/unpolluted/my-app.jar">
        <fileset dir="${location.dist.binaries}/exploded/my-app.jar"/>
    </copy>
    <jar destfile="${location.dist.binaries}/my-app-unpolluted.jar">
        <fileset dir="${location.dist.binaries}/unpolluted/my-app.jar"/>
    </jar>
</target>

It's a bit grungy, but it achieves what you want.

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