我尝试将插件写入 NetBeans IDE。但是我在找到某些图像的正确路径时遇到了问题:
这是我的项目树结构:
并像这样测试代码显示图标 wePagesBadge.gif
ImageIcon image = new ImageIcon("webPagesBadge.gif");
JOptionPane.showMessageDialog(null, "Some Messsage","Example",JOptionPane.INFORMATION_MESSAGE,image);
当然,当我将此图像放入我在本地计算机上安装的 netbeans 的根文件夹中时,图标会出现在 JOptionPane 中。这条路是
C:\Program Files\NetBeans 8.0
另一个例子是当我不使用 Maven 项目类型来开发插件,而是使用 Netbeans 模块项目类型时:
这次图像出现在 JOptionPane 上。我花了很多时间寻找答案,但我不知道如何解决。
最佳答案
将资源放在源码包下是不好的做法
在 src/main/resources 下创建一个我的资源名称的文件夹,然后尝试使用
读取它className.class.getClassLoader().getResource("yourImageFile");
所以这应该可以完成工作
ImageIcon imageIcon = new ImageIcon(PDFGenerator.class
.getClassLoader()
.getResource("yourIcon.gif"));
关于java - 如何在 Netbeans 平台 Maven 插件中找到图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25555711/