Persisting Data on the Service or Activator Level

I have been trying to save data to and from a file in the Activator object. I need to store some plugin specific configurations mainly to set the configuration.setUserInsertable(boolean) property in the program node services. I can read resource files from the .jar package, but have not found a way to write to it yet.

I have found two other ways to store files:

  1. using the frameworks bundleContext.getDataFile(String filename) method
  2. using an absolute path to the ‘/programs/’ folder

I don’t want my plugins configuration files to litter the filesystem, I want the files to be deleted when the plugin is uninstalled. What is the best method for achieving this?

I can speak only from OSGi (underlying mechanism) perspective. The first way you mention is local to actual bundle (module/extension) version. When it will be uninstalled this data should be rolled out.

Reference:
https://docs.osgi.org/javadoc/osgi.core/7.0.0/org/osgi/framework/BundleContext.html#getDataFile-java.lang.String-

2 Likes