【问题标题】:Exclude empty directories with Jar Jar Links使用 Jar Jar Links 排除空目录
【发布时间】:2011-12-11 16:24:51
【问题描述】:

我正在使用来自Jar Jar Links 的 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”选项 (listed in the doc),但没有奏效。

【问题讨论】:

    标签: ant jarjar


    【解决方案1】:

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

    鉴于这是在大约三年前提出的并且似乎没有任何吸引力,我想您的选择是提供修复或解决它。

    利用 Ant 对删除副本中空目录的支持来解决它的一个示例 Ant 目标是:

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

    它有点邋遢,但它实现了你想要的。

    【讨论】:

    • 这似乎对我有用(我必须转换为 Gradle 语法)。
    猜你喜欢
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2012-01-23
    • 2021-08-28
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多