eclipse 我可以将多个 jar 文件合并到一个 jar 文件中吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5089565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can i combine many jar files in one jar file
提问by crowne
I have multiple JAR files, which I have to add to classpath in Eclipse.
我有多个 JAR 文件,我必须将它们添加到 Eclipse 的类路径中。
Is it possible to combine 30 files in one file and include that file?
是否可以将 30 个文件合并到一个文件中并包含该文件?
回答by Jon Skeet
You can, but I don't think it would necessarily be a good idea to do so. Three possible reasons, and no doubt there are more:
你可以,但我认为这样做不一定是个好主意。三个可能的原因,毫无疑问还有更多:
- It makes it harder to see where any one constituent file comes from.
- It makes it harder to replace just one library
- If there are files which are contained in multiple jar files, which should "win"? For example, all the jar files will have their own manifest... you may be able to merge them all, but not necessarily... and for other files there may well simply not be a sensible way of merging them.
- 这使得查看任何一个组成文件的来源变得更加困难。
- 仅替换一个库变得更加困难
- 如果存在包含在多个 jar 文件中的文件,哪个应该“获胜”?例如,所有 jar 文件都有自己的清单……您可以将它们全部合并,但不一定……对于其他文件,合并它们可能根本就不是一种明智的方式。
My vote is to keep the jar files separate.
我的投票是将 jar 文件分开。
回答by Chris
回答by crowne
回答by Umesh K
This question seems probable duplicate. Please try to find answer from similar article in this forum Clean way to combine multiple jars
这个问题似乎很可能重复。请尝试从本论坛的类似文章中找到答案 Clean way to combine multiple jars
回答by Patrick
There is another thread here that explains how to package jars for releases, including using Ant, jarjar and eclipse plugins.
这里有另一个线程解释了如何为发行版打包 jar,包括使用 Ant、jarjar 和 eclipse 插件。
回答by AlexR
First, you can. JAR is just a ZIP file. You can extract all stuff into one directory, then create zip file (even manually using WinZip or similar tool), call the result *.jar (if you wish) and add it into the classpath.
首先,你可以。JAR 只是一个 ZIP 文件。您可以将所有内容提取到一个目录中,然后创建 zip 文件(甚至可以手动使用 WinZip 或类似工具),调用结果 *.jar(如果您愿意)并将其添加到类路径中。
The only problem that will probably happen is if several jar files contain resources with the same name (and path). for example, manfest.mf, or other descriptors. In most cases it will not cause any problem but sometimes if application code uses these resources you can have trouble.
唯一可能发生的问题是,如果多个 jar 文件包含具有相同名称(和路径)的资源。例如,manfest.mf 或其他描述符。在大多数情况下,它不会导致任何问题,但有时如果应用程序代码使用这些资源,您可能会遇到问题。
There are some automatic tools that do this. Take a look on JarJar.
有一些自动工具可以做到这一点。看看 JarJar。
BUT the more important question: why do you want to do this? If you do not use maven put all library jars to one directory named lib under your project. Then add all these jars to your classpath in eclipse using 2-3 clicks. That's it.
但更重要的问题是:你为什么要这样做?如果您不使用 maven,请将所有库 jar 放在您的项目下一个名为 lib 的目录中。然后单击 2-3 次将所有这些 jar 添加到 eclipse 中的类路径中。就是这样。
if you are using maven, include all your direct dependences into your pom.xml, compile the project, then say mvn eclipse:eclipse
. This will create .classspath and .project for you. Now just use it.
如果您使用的是 maven,请将所有直接依赖项包含到 pom.xml 中,编译项目,然后说mvn eclipse:eclipse
. 这将为您创建 .classspath 和 .project 。现在只需使用它。
回答by Sjoerd
Jar files are just ZIP files, so you can try to unzip all jars, put all files together and then ZIP them again.
Jar 文件只是 ZIP 文件,因此您可以尝试解压缩所有 jar,将所有文件放在一起,然后再次 ZIP。