Accessing resource files within your Eclipse plugins

Posted by Mike Haller on Friday, December 29. 2006 at 00:00 in Eclipse
Sometimes, especially in the development phase, you want to get your Eclipse Plugin's absolute file system location on the disk. Usually, you want to have a java.io.File. Since Eclipse mainly uses URLs to locate resources, it's not an easy one-liner to get the location. However, the utility class org.eclipse.core.runtime.FileLocator comes to the rescue:

URL bundleRoot = getBundle().getEntry("/");
URL fileURL = FileLocator.toFileURL(bundleRoot);
java.io.File file = new java.io.File(fileURL.toURI());

System.out.println("Bundle location:" + file.getAbsolutePath());


Note: please be aware that your plugin should be normally packaged as jar file and thus the above code does not work any more in a packaged deployment! To get this working, you must set the unpack attribute in your feature for the plugin.

What you really want to do is to use getBundle().getEntry("/file.txt").openStream() to get the contents of a file which is located within your plugin.

The code above is called from within a Plugin Activator class and uses the shortcut getBundle() method. If you need the code outside of an Activator class, use the Platform to resolve the bundle first. A one-liner looks like this:

new File(FileLocator.toFileURL(Platform.getBundle(
     pluginId).getEntry("/")).toURI());


Optionally Required

Posted by Mike Haller on Thursday, December 28. 2006 at 00:00 in Eclipse
Ever wondered what the error message Missing optionally required bundle means?
!SUBENTRY 2 org.eclipse.emf.edit.ui 2 0 2007-01-02 16:42:41.082 !MESSAGE Missing optionally required bundle org.eclipse.ui.ide_[3.2.0,4.0.0).


Eclipse tries to tell you that the bundle org.eclipse.emf.edit.ui can make use of org.eclipse.ui.ide, but it is not strictly necessary for emf.edit.ui to work. In fact, emf.edit.ui uses services from ui.ide if they are existant. If not, it just doesn't use them.

The error message in the /configuration/.log is not an error message, but more an informative level message.

So, if your RCP application doesn't start and you find this message in the .log file, you can safely ignore it and focus on resolving the other messages first.

Product Launcher Icons

Posted by Mike Haller on Wednesday, December 27. 2006 at 00:00 in Eclipse
If you want to brand your Eclipse RCP product launcher with your own icons, you need to either supply some bitmaps or a single Windows Icon file. The problem here, besides the boring work of creating 7 similar files, is that you need some of them in 32-bit. None of the usual imaging tools I have installed were capable of creating 32 Bit Windows Bitmaps: Irfanview, The Gimp, .. not even Microsoft Paint of Windows XP could create this format.

Use the Eclipse Product Editor to specify which Icons to use for the Launcher Executable


Once again, the Eclipse IRC channel #eclipse on Freenode came to the rescue and provided some hints: The Microsoft MSDN Library contains a tool which can be used to create the 32 Bit Bitmaps used for Windows XP. However, I choosed to evaluate a tool named Microangelo Studio to creat the .ico File. Pasting the product logo into the editor and adding a new format for each of the required dimensions and color depths.

The last thing I need to do is to explain all that to my designer. My logos are pretty ugly and haven't even transparent background. This looks like Windows 3.0 and will probably frighten the users.

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch

Archives