如何在我的 Netbeans 项目中包含外部 jar [英] How can I include external jar on my Netbeans project

查看:29
本文介绍了如何在我的 Netbeans 项目中包含外部 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行clean and build"时,正在创建的 .jar 文件仅在 lib 文件夹位于 的同一文件夹中时才会运行.jar 文件.

When I run "clean and build" the .jar file that is being created only runs if the lib folder is at the same folder of the .jar file.

因此,如果我将 jar 文件移动到桌面并将 lib 文件夹保留在 dist 文件夹中,则 jar 文件会给我一个例外.

So if I move the jar file to the desktop and leave the lib folder in the dist folder, the jar file will give me an exception.

我该如何处理这个问题?

How can I deal with this problem?

推荐答案

如果您将 jar 复制到源代码目录中,它们将在您的最终 jar 中.尽管如此,我不确定这是否会在 100% 的时间内有效.

If you copy your jars into the source code directory, they will be in your final jar. Nevetheless, I am not sure if this will work 100% of the time.

java-forum 声明如下:

除了少数几种情况外,最适合我的是只需手动合并文件..jar 基本上是一个 .zip有组织的内容,您几乎可以使用任何支持 .zip 格式的文件打开它们归档程序(我只使用 gnome 的标准归档程序 File Roller,并且效果很好).备份您的 jar 文件并在存档器中打开它根据您的选择,并对库中的每个库 jar 执行相同操作目录.拖放工作文件夹(IE,除META-INF 目录)从每个库到您的 jar 的根路径(连同您的 META-INF 和您的应用程序的根包).现在拖动META-INF/MANIFEST.MF 文件从您的 jar 到您的桌面或任何其他文件夹.打开它,并擦除 Class-Path 和 X-COMMENT 行.别忘记在文件末尾留下一个空白的换行符!保存新的manifest 文件并将其拖回 jar 的 META-INF 目录,覆盖旧的.测试罐子.

Except for a select few circumstances, what works best for me is to simply merge the files manually. A .jar is basically a .zip with organized contents, and you can open them in almost any .zip capable archive program (I just use gnome's standard archiver, File Roller, and it works great). Backup your jar file and open it in the archiver of your choice, and do the same for each library jar in the library directory. Drag and drop the working folders (IE, everything EXCEPT the META-INF Directory) from each library into your jar's root path (alongside your META-INF and your app's root package). Now drag the META-INF/MANIFEST.MF file from your jar to your Desktop or any other folder. Open it, and erase the Class-Path and X-COMMENT lines. Don't forget to leave a blank newline at the end of the file! Save the new manifest file and drag it back to your jar's META-INF directory, overwriting the old one. Test the jar.

这篇关于如何在我的 Netbeans 项目中包含外部 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆