2011-12-11 65 views
8

我使用Jar Jar Links的Ant任务将第三方jar文件(objenesis)中的类嵌入到我的可分发jar文件(example.jar)中。 Jar Jar会将原始包(org.objenesis)中的课程转换为我选择的课程之一。用Jar Jar链接排除空目录

它可以工作,但它会在可分发的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="[email protected]"/> 
    </jarjar> 
</target> 

的example.jar构成的内容的样品包括(如预期):

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

,但也是这些空目录(不需要e):

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

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

我尝试了“zap”选项(listed in the doc),但那不起作用。

回答

7

这似乎是在瓶瓶一个已知的问题,在问题跟踪上市:http://code.google.com/p/jarjar/issues/detail?q=empty&id=32

鉴于这几乎是三年前提出的,并没有出现已经有任何牵引,我想你的选择将提供修补程序或解决此问题。

一个例子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="[email protected]"/> 
    </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> 

这是一个有点蹩脚,但它达到你想要什么。

+0

这似乎适用于我(我不得不转换为Gradle语法)。 –