Question

I am building an RCP application. I have only one plugin project and I'm trying to export as product. I use an sqlite database file . While I am testying both my application and my product from Run of eclipse having NO PROBLEM at all, when I export the product , database access fails. This is how I open the database connection

dbConnection = DriverManager.getConnection("jdbc:sqlite:"+FileLocator.resolve(Platform.getBundle("BundleID").getEntry("dbFile")).getPath());

My dbFile is in my projects root file, and after the export , it is found in the BundleID.jar in the plugins folder, and so the application cannot open it as the path calculated is sth like.... "/plugins/BundleId.jar!/dbFile"

The "!" before / is in the String!!!

Is there Something I could do in order to overcome this?

Was it helpful?

Solution

Use FileLocator.toFileURL() on the URL returned by FileLocator.resolve() to get a more normal URL.

Note: this will expand your jar in to a temporary cache so that a normal file URL can be returned. This cache is not guaranteed to be persistent so if you want database changes to persist you need to put the database somewhere else.

One possibility is to copy the database to the workspace .metadata in the plugin state data (see Platform.getStateLocation(bundle).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top