The eclipse infrastructure provides every plugin with an individual subdirectory in the metadata directory of the workspace. This subdirectory is also named plugin state directory.
In this subdirectory of the workspace, a plugin can place all kind of data it would like to. This can reach from custom configuration files up to any resources that need to be persisted.

To place default files in this state directory, the Activator class of a plugin can be customized.
The following code snipped presents a customized start() method of an Activator class. It checks the existence of a file named config.txt in the plugins state directory. If it does not exist yet, it will be created with a setting of a default port configuration.

public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// create the default configuration file
IPath stateLocation = Activator.getDefault().getStateLocation();
File stateFile = stateLocation.append("config.txt").toFile();
if(!stateFile.exists()){
PrintWriter writer = new PrintWriter(stateFile);
writer.println("PORT=8080");
writer.close();
}
}

Create Custom File During Plugin Deployment

Post navigation


Leave a Reply