将 java 库导出为 .jar 文件

发布于 2024-12-06 13:38:33 字数 371 浏览 1 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-12-13 13:38:33

最简单的方法是也发送 JAR 库文件并向清单添加一个 Class-Path 条目。该条目如下所示:

Class-Path: objectdraw.jar

您还可以手动设置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:

Class-Path: objectdraw.jar

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.

如果没有 2024-12-13 13:38:33

事实证明,我发现执行此操作的最佳方法是解压缩库,然后将所有生成的文件与最终存档一起放入。这样它实际上可以在其他计算机上运行。

jar xf library_wanted.jar; jar cvmf MANIFEST.mf end_result.jar *.class library_wanted/

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.

jar xf library_wanted.jar; jar cvmf MANIFEST.mf end_result.jar *.class library_wanted/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文