java - 有没有办法从当前插件访问其他插件的资源文件夹?

标签 java eclipse-rcp rcp

我正在使用以下代码将插件“A”的资源文件夹中可用的图标复制到本地文件夹。这绝对没问题。现在我想知道是否有办法从其他插件(插件 B)的资源文件夹中复制图标。我必须只保留插件 A 中的复制逻辑。有没有办法从当前插件访问其他插件的资源文件夹?

File objectDir = new File(directory + "/icons/");

    if (!objectDir.exists()) {
        objectDir.mkdirs();
    }

    InputStream inStream = null;
    OutputStream outStream = null;

    try {

        File bfile = new File(directory + "/icons/validation.png");
        inStream = this.getClass().getClassLoader().getResourceAsStream("/icons/viewAsHTML.png");   
        outStream = new FileOutputStream(bfile);

        byte[] buffer = new byte[1024];

        int length;
        // copy the file content in bytes
        while ((length = inStream.read(buffer)) > 0) {

            outStream.write(buffer, 0, length);

        }

        inStream.close();
        outStream.close();

        System.out.println("File is copied successful!");

    } catch (IOException e) {
        e.printStackTrace();
    }

最佳答案

您应该能够使用platform:/plugin/机制获取另一个插件中的资源:

url = new URL("platform:/plugin/your.plugin.package.pluginB/icons/validation.png");
InputStream inputStream = url.openConnection().getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));

关于java - 有没有办法从当前插件访问其他插件的资源文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16169156/

相关文章:

java - 如何在 E4 应用程序中注入(inject)自定义单例 bean?

java - 尝试多个透视图时,RCP 中未加载透视图

java - 在Win7上为SWT/RCP应用程序设置ApplicationId

java - JSNI Marshal Enum 可以作为字符串吗?

javascript - 如何使用 Selenium Webdriver 处理从 DOM 中删除的 Web 元素?

Maven (with tycho) 在实现产品时失败

java - 如何在应用程序启动时选择 Handle MenuItem

java - 使用 Android 开发卡在 Eclipse 中的模拟器屏幕上?

java - 如果文件中的字符串可能包含任意字符,您将如何分隔它们?

java - Java 桌面应用程序基于 XML 或 HTML 的 UI