【发布时间】:2015-04-23 02:48:40
【问题描述】:
我有一个代码,我在其中创建 Java 操作并尝试将图标与它们相关联。一个代码快照是
FileOpenCommand fileOpen = new FileOpenCommand(this);
fileOpen.putValue("ImageOnly", false);
fileOpen.putValue(Action.NAME, "Open");
fileOpen.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../resources/File-Open-icon24x24.png")));
fileOpen.putValue(Action.SHORT_DESCRIPTION, "Opens the existing file.");
fileOpen.putValue("Group", "File");
fileOpen.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
this.commands.put("FileOpen", fileOpen);
重音在我尝试将 Action.SMALL_ICON 属性设置为操作的那一行。这在 NetBeans 环境中以调试或发布模式执行时有效。但是当我尝试从命令行执行 jar 文件时,它失败并出现异常。
有什么想法吗?与类路径有什么关系?资源文件夹作为包放在主包中。
提前致谢!
【问题讨论】:
-
资源在 JAR 中吗?
-
是的,是的。主包是controllz.mmi,资源包是controllz.mmi.resources。 5he 试图获取资源的类位于 controllz.mmi.models 包中。如前所述,它从 bean IDE(运行和调试)而不是从命令行使用 java -jar Controllz_MMI.jar 工作。 Jar 文件被放到 beans 项目的“dest”子文件夹中,我尝试从那里运行它...
标签: java image netbeans jar resources