A Kind Of Magic


For several weeks I was wondering how to embedded one of my SQLIte database in my plugin. Sqlite database are simply binary files. Until now my plugin was loading the database using a hard coded path !!!! What a bad solution causing lot of nightmares for any developer !!!!

Today I had to export my plugin and as a consequence I had to find a solution.

Here the Eclipse magic operated once again. I took a look at FileLocator class.

Every Eclipse Plugin developer HAVE to know this class.

The find(bundle, path, override) method allowed me to get an URL for my database file. Then the toFileURL(url) allowed me to convert this URL into an other URL using the file protocol.

Here the magic operates: I was wondering how my JDBC driver would be able to load a database from a Jar file …. In fact this driver is not able to do that but Eclipse was clever enough according to the toFileUrl method Javadoc to:

“The contents of the URL may be extracted into a cache on the file-system in order to get a file URL”

Eclipse copies in that case my database file into the configuration directory of my Eclipse’s installation. This way my JDBC driver was able to load the database since it loaded it from a local file as it did for a hard coded file path !!!!

Thanks Eclipse

Advertisements

3 thoughts on “A Kind Of Magic

  1. In fact I am not using cache to persist data. The persisted data is a resource in my plugin jar.

    The cache is used by the platform when I need an access using the file protocol for this persisted data.

    The next time I’ll need to access it I guess Eclipse will put it again in the cache.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s