如何使用 ant 解压多个 JAR 文件并将它们重建为一个 JAR 文件?
我想解压多个 JAR 文件,然后使用 ant 构建脚本将其重建为一个 JAR。这可能吗?
I would like to unjar multiple JAR files and then rebuild into one JAR using an ant build script. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,用蚂蚁是可以的。 jar 文件基本上是带有特殊清单文件的 zip 文件。因此,要解压,我们需要解压罐子。 Ant 包含一个 unzip 任务。
要解压缩/unjar 项目中的所有 jar 文件:
显然,您需要首先声明 ${build.dir} 和 ${lib.dir} 。
行告诉 ant 包含所有以 jar 扩展名结尾的文件,您可以调整包含内容以满足您的需要。要将所有内容打包到 jar 中,请使用 jar 任务:
在此示例中,我们包含不同的文件集。在一个文件集中,我们包含所有已编译的类。在另一个文件集中,我们包含该特定项目所依赖的两个配置文件。
Yes, it's possible with ant. A jar file is basically a zip with a special manifest file. So to unjar, we need to unzip the jars. Ant includes an unzip task.
To unzip/unjar all the jar files in your project:
Obviously you need to declare ${build.dir} and ${lib.dir} first. The line
<include name="**/*.jar" />
tells ant to include all files that end up with the jar extension, you can tweak that include to suit your needs.To pack everything into a jar, you use the jar task:
In this example, we include different filesets. In one fileset we are including all compiled classes. In another fileset we include two config files that this particular project depends upon.
是的 !
你有两种可能性:
如果您不需要排除某些 jar 中的内容(例如某些可能覆盖您的属性配置文件等),这非常有用。这里的 excepts 属性是从 dir 属性中过滤掉文件。
另一种解决方案是使用 zipfileset 标记,其中 excepts 属性这次将从要合并的 jar 中过滤掉内容。
Yes it is !
You have two possibilities :
This is useful if you don't need to exclude content that are in some jars (like for example some properties configuration file that might override yours, etc). Here the excludes properties is filtering out files from the dir property.
The other solution is to use the zipfileset tag where the excludes property this time will filter out content from the jar to be merged.
是的,这是可能的。
一种可能的解决方案是从给定目录中的所有 jar 文件创建一个 jar 文件:
Yes, it's possible.
One possible solution that creates one jar file from all the jar files in a given directory:
还有一个专门用于重新打包 jar 的项目,名为 JarJar。您可以使用它将多个 Jars 重新打包为一个。根据您的要求,您甚至可以重命名类以防止版本冲突。
从他们的入门页面:
在此示例中,我们包含来自 jaxen 的类.jar 并添加一条规则,将任何以“org.jaxen”开头的类名更改为以“org.example.jaxen”开头(在我们的想象世界中,我们控制 example.org 域):
There is also a project devoted to repackage jars called JarJar. You can use it to repackage mutiple Jars into one. Depending on your requirements, you can even rename classes to prevent version conflicts.
From their getting started page:
In this example we include classes from jaxen.jar and add a rule that changes any class name starting with "org.jaxen" to start with "org.example.jaxen" instead (in our imaginary world we control the example.org domain):