I have 2 plguins A and B. In MANIFEST.MF A , I have plugin B in the Require-Bundle section. But when I try to get resource B from A , for example
ClassFromA.class.getClassLoader().getResource('resource_from_B')
I get null . If I put a B resource (folder) in A , everything works like a charm. Am I missing something?
NOTE. I am reading a Lars Vogel article
Bundle bundle = Platform.getBundle("de.vogella.example.readfile"); URL fileURL = bundle.getEntry("files/test.txt"); File file = null; try { file = new File(FileLocator.resolve(fileURL).toURI()); } catch (URISyntaxException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); }
^ this solution works when I run my plugin from eclipse, but when I pack it in jar and try to install from the local update site, I get
java.lang.IllegalArgumentException: URI is not hierarchical
PS I also read a few relative questions in StackOverflow, but couldn't find the answer:
- Java Jar file: use resource errors: URI is not hierarchical
- Why is my URI not hierarchical?
SOLUTION: Thank you very much @ greg-449. Therefore, the correct code is:
Bundle bundle = Platform.getBundle("resource_from_some_plugin"); URL fileURL = bundle.getEntry("files/test.txt"); File file = null; try { URL resolvedFileURL = FileLocator.toFileURL(fileURL);
NOTE: also important use the 3-arg URI constructor to properly remove file system characters.
eclipse eclipse-plugin eclipse-rcp
Ilya Buziuk
source share