【发布时间】:2012-12-09 00:18:31
【问题描述】:
我创建了一个桌面应用程序,但在生成的可运行 jar 中遇到了问题。在 Eclipse 环境中一切正常,但是当我生成 jar 时,它只显示swtcomponents(菜单、选项卡等)。
其他库的位置是空白区域(生成图库的库)。同样不出现set ToolBar(含带图片的按钮),GoogleMap.html不出现。
如何正确生成包含这些外部源的可执行 jar?
工具栏图片加载代码:
folderSearchIcon = new Image(display, this.getClass().getResourceAsStream("images/search_folder.png"));
GoogleMap.html 加载代码:
File mapFile = new File("resources/GoogleMap.html");
if(!mapFile.exists()) {
System.out.println("File doesn't exist! " + mapFile.getAbsolutePath());
return;
}
生成可运行的 jar:
我在 Eclipse 中的应用结构和生成的 jar 结构:
生成的清单:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ swt.jar commons-imaging-1.0-SNAPSHOT.jar org.eclip
se.nebula.widgets.gallery_0.5.3.201210262156.jar xmpcore.jar metadata
-extractor-2.6.3.jar
Class-Path: .
Rsrc-Main-Class: geotagger.AppInit
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
【问题讨论】:
-
通过runnable jar运行应用时,后台有没有异常?
-
您确定资源确实包含在 jar 中吗?只需使用存档软件打开并检查即可。
-
所以
lib文件夹不包含在 jar 中,对吗?只需使用 Eclipse 将它们添加到构建路径 -
@NikolayKuznetsov 从清单和第二个屏幕截图中可以看出,库在 jar 中被引用。
-
@unixhead 根据您的屏幕截图,您的 jar 不包含
resources文件夹,但您使用它来访问.html文件。
标签: java eclipse swt executable-jar