将 java 库导出为 .jar 文件
我对 java 还很陌生,而且对导出 .jar 文件也很陌生。我有一个小游戏想发送给一些朋友,在另一个问题中我被告知我应该将其导出到可执行 jar 文件。好吧,我终于在我的计算机上运行了,但是当我将其发送给其他人时,它不起作用,因为他们没有该库。
我正在导入 objectdraw 库,如果没有它,我的程序将根本无法运行!
所以基本上我需要找到一种方法将对象绘制库导出为我的 .jar 文件的一部分,以便他们也可以使用它。我是否只需将其包含在 jar 命令的包含文件部分中? 例如:jar cmf MANIFEST.mf Archery.jar * /System/Library/Java/Extensions/objectdraw.jar
还是什么?我现在正在使用命令行工作。
I'm still pretty new to java and I'm VERY new to exporting .jar files. I've got a little game that I want to send to some friends and I was told in another question that I should export it to an executable jar file. Well I finally got that working on my computer but when I send it to other people it doesn't work because they don't have the library.
I'm importing the objectdraw library and without that my program won't run at all!
So basically I need to find a way to export the object draw library as part of my .jar file so that they can use it too. Do I simply include it in the included files part of the jar command?
ex: jar cmf MANIFEST.mf Archery.jar * /System/Library/Java/Extensions/objectdraw.jar
or what? I'm working out of the command line right now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是也发送 JAR 库文件并向清单添加一个
Class-Path
条目。该条目如下所示:您还可以手动设置
CLASSPATH
环境变量。或者,您可以解压缩库并将所有(或仅所需的文件)添加到最终的 jar 中。但这并不总是有效,因为某些库依赖于其 JAR 文件的完整性。
最后,可以将依赖项包含在主 JAR 中,但需要自定义类加载器。
The simplest way is to send the JAR library file too and add a
Class-Path
entry to the manifest. This entry would look like:You could also set the
CLASSPATH
environment variable manually.Alternatively, you can unpack the library and add all (or just the required files) to your final jar. This doesn't always work though, because some libraries rely on the integrity of teir JAR file.
Finally, it is possible to include the dependency in the main JAR, but it would require a custom class loader.
事实证明,我发现执行此操作的最佳方法是解压缩库,然后将所有生成的文件与最终存档一起放入。这样它实际上可以在其他计算机上运行。
Turns out the best way I've found to do this is to unpack the library and then put all the resulting files in with your final archive. This way it actually works on other computers.