猿问

组合多个罐子的干净方法?最好使用蚂蚁

我对某些外部jar具有运行时依赖性,我希望将这些外部jar重新“打包”成单个jar。这些外部依赖项存储在external_jars目录中,我希望不必全部列出它们(即,如果我的依赖项发生更改,则无需更改构建脚本)。有什么想法吗?


Google为我提供了一个很好的答案-如果您不介意将每个jar作为依赖项列出:


http://markmail.org/message/zijbwm46maxzzoo5


大致来说,我需要遵循以下内容,它将lib目录中的所有jar合并到out.jar中(带有一些合理的覆盖规则)。


jar -combine -out out.jar -in lib/*.jar


暮色呼如
浏览 479回答 3
3回答

DIEA

只需zipgroupfileset与Ant Zip任务一起使用<zip destfile="out.jar">&nbsp; &nbsp; <zipgroupfileset dir="lib" includes="*.jar"/></zip>这将拉平所有包含的jar库的内容。

喵喔喔

弗拉基米尔的答案是正确的,但我认为他的建议暗示将所有罐子重新包装在一个大的out.jar中,然后将其作为单个<zipfileset>或类似的内容输入到Ant Jar任务中。此两步方法是不必要的。我不确定这是否与Ant版本有关,但是我有Ant 1.7.1,其<jar>任务为谅解<zipgroupfileset>,它可以直接提供第三方jar的所有内容。<jar destfile="MyApplication.jar">&nbsp; <zipgroupfileset dir="lib" includes="*.jar" />&nbsp;&nbsp; <!-- other options -->&nbsp; <manifest>&nbsp; &nbsp; <attribute name="Main-Class" value="Main.MainClass" />&nbsp; </manifest></jar>

莫回无

尝试先将JAR提取到编组目录中:<target name="combine-jars">&nbsp; &nbsp; <mkdir dir="${marshall.dir}"/>&nbsp; &nbsp; <unzip dest="${marshall.dir}">&nbsp; &nbsp; &nbsp; &nbsp; <fileset dir="${external.jar.dir}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <include name="**/*.jar"/>&nbsp; &nbsp; &nbsp; &nbsp; </fileset>&nbsp; &nbsp; </unzip>&nbsp; &nbsp; <jar destfile="${combined.jar}" basedir="${marshall.dir"}>&nbsp; &nbsp; <delete dir="${marshall.dir}"/></target>这里${marshall.dir}是一个临时目录,${external.jar.dir}是您保留JAR的位置,并且${combined.jar}是目标JAR。
随时随地看视频慕课网APP

相关分类

Java
我要回答