java 您可以在 jar 文件中添加多个 jar 然后启动该 jar 文件吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/531353/
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 you add multiple jars in a jar file and then launch that jar file
提问by Berlin Brown
I am working on a GUI application and would rather distribute just one jar as opposed to multiple ones.
我正在开发一个 GUI 应用程序,宁愿只分发一个 jar 而不是多个 jar。
Can you control this with the manifest.
你能用清单来控制这个吗?
回答by Sam
Another option is to use a custom class loader such as this one:
另一种选择是使用自定义类加载器,例如:
回答by Fortyrunner
You need to be careful when doing this. If the jars you are merging have manifest files with critical information - these can get lost, only the last file will get merged.
执行此操作时需要小心。如果您正在合并的 jars 包含带有关键信息的清单文件 - 这些文件可能会丢失,只有最后一个文件会被合并。
E.g. If you merge JavaMail - the manifest file is important. If you lose it - bad things csn happen.
例如,如果您合并 JavaMail - 清单文件很重要。如果你失去了它 - csn 会发生不好的事情。
The safest thing to do is to look at each jar file and check the manifest file.
最安全的做法是查看每个 jar 文件并检查清单文件。
回答by Sunil Kumar Sahoo
回答by kanaparthikiran
Create a Shaded jar which combines multiple jars into a single jar. Maven supports this functionality out of the box.
创建一个 Shaded jar,它将多个 jar 组合成一个 jar。Maven 开箱即用地支持此功能。

