In a RCP application development, I'm trying using a browser(org.eclipse.swt.browser.Browser) component to load local html file bundled in a plug-in. The plug-in project file structure is like below:
project-name
+-/src
+-/html
+/META-INF
...
In code, I use the below code to load html file:
String html = "/html/index.html";
URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(html), null);
url = FileLocator.toFileURL(url);
browser.setUrl(url.toString());
This html file (index.html) references some css file, javascript file and other html file. These resources resist in html folder. The above code works well in Eclipse development environment. But when I export to a RCP product, it loads this index.html, but the html file display layout is a chaos. I tried to find what happened, so I looked for the resource in my product workspace. I found a file named index.html in product workspace, but no other resources found. I think it's the cause. But how to solve this problem? Thanks!
Ju Xiaomi
The FileLocator.toFileURL(url)
method copies the resource from inside the plugin jar in to a temporary location so that it can return a file. Since you are not doing the same for the other resources the html will not be able to find them.
You can call FileLocator.toFileURL
on all the required resources to get them all in the temporary location.
You can also specify that the plugin should not be compressed in to a jar so that FileLocator.toFileURL
does not need to use the temporary location. You can do this by specifying
Eclipse-BundleShape: dir
in the plugin MANIFEST.MF
Note: If the plugin is part of a feature then the 'unpack the plugin archive open after installation' should be specified for the plugin in the feature.