read a file from inside the plugin jar. [message #660506] |
Fri, 18 March 2011 13:11  |
Eclipse User |
|
|
|
Hi All,
I have some files in my plugin that contain template data for my wizards, I have the strange situation that I can run the plugin successfully in the test environment, (pressing on "launch Eclipse application"), but when I try to export the plugin in a jar and deploy it in a different eclipse installation, I get the following exception:
Quote: | Caused by: java.lang.RuntimeException: uri was opaque. filename was: /resources/erroneousSectionsFile.ini uri was: jar:file:/D:/Users/Me/My%20Documents/eclipse/plugins/com.myC ompany.plugin_1.0.0.alpha.jar!/resources/erroneousSectionsFi le.ini
at org.myCompany.qat.plugin.Activator.getInternalFile(Activator .java:202)
|
I raise the exception when the URI is Opaque (it would have been thrown anyways from the constructor of java.lang.File).
Any Idea about what's the problem here?
Below the code of the getInternalFile method as I wrote it (obviously the line 202 is the one with the throw new RuntimeException):
Quote: | public static File getInternalFile(String filename) {
Bundle bundle = Platform.getBundle(PLUGIN_ID);
URL fileURL = bundle.getEntry(filename);
if (fileURL == null) {
throw new RuntimeException(
"fileUrl was null when searching for file: " + filename);
}
File file = null;
try {
URL resolved = FileLocator.resolve(fileURL);
try {
String clean = resolved.toString().replace(" ", "%20");
resolved = new URL(clean);
} catch (MalformedURLException e1) {
throw new RuntimeException("Problems cleaning the URL: "
+ fileURL, e1);
}
URI uri = resolved.toURI();
uri = uri.normalize();
if (uri.isOpaque()) {
throw new RuntimeException("uri was opaque. filename was: "
+ filename + " uri was: " + uri.toString());
}
file = new File(uri);
} catch (URISyntaxException e) {
throw new RuntimeException(
"internal pluging error: Filename is incorrect could not be resolved: "
+ fileURL, e);
} catch (IOException e) {
throw new RuntimeException(
"internal pluging error: could not find file" + fileURL, e);
}
return file;
}
|
How would you obtain a File from inside the bundle jar?
Thanks a lot in advance,
Giulio
[Updated on: Fri, 18 March 2011 13:13] by Moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.52584 seconds