如何为 Eclipse Natures Project 保存自定义对象?
How to save custom object for Eclipse Natures Project?
我正在开发具有自定义项目性质的 Eclipse 插件。我需要将一些关于我的项目的自定义信息保存到工作区中。例如,我的项目必须使用多个数据库连接信息,这些信息放在 List<DbConfig>
中。下面是DbConfig class:
public class DbConfig {
private String dbName;
private String connectionString;
private String username;
private String password;
//... getters and setters
}
我需要这样的想法,但想放入首选项对象类型:
IProject project = ... get project from selection or something
IScopeContext context = new ProjectScope(project);
Preferences projectPreferences = context.getNode("your nature id");
projectPreferences.put(key, value);
projectPreferences.flush();
我应该在哪个对象中放置此列表和其他一些首选项?
您不能在首选项存储中存储对象。
您可以在 'state location' 中为您的插件保存任何您喜欢的数据。
使用以下方法获取州位置:
Bundle bundle = ... your plugin bundle
IPath path = Platform.getStateLocation(bundle);
返回的 IPath
值将在工作区元数据区域中。
您可以为每个项目使用一个单独的文件。
您可以通过以下方式获得您的 Bundle
:
Bundle bundle = FrameworkUtil.getBundle(getClass());
或
Bundle bundle = Platform.getBundle("your plugin id");
我正在开发具有自定义项目性质的 Eclipse 插件。我需要将一些关于我的项目的自定义信息保存到工作区中。例如,我的项目必须使用多个数据库连接信息,这些信息放在 List<DbConfig>
中。下面是DbConfig class:
public class DbConfig {
private String dbName;
private String connectionString;
private String username;
private String password;
//... getters and setters
}
我需要这样的想法,但想放入首选项对象类型:
IProject project = ... get project from selection or something
IScopeContext context = new ProjectScope(project);
Preferences projectPreferences = context.getNode("your nature id");
projectPreferences.put(key, value);
projectPreferences.flush();
我应该在哪个对象中放置此列表和其他一些首选项?
您不能在首选项存储中存储对象。
您可以在 'state location' 中为您的插件保存任何您喜欢的数据。
使用以下方法获取州位置:
Bundle bundle = ... your plugin bundle
IPath path = Platform.getStateLocation(bundle);
返回的 IPath
值将在工作区元数据区域中。
您可以为每个项目使用一个单独的文件。
您可以通过以下方式获得您的 Bundle
:
Bundle bundle = FrameworkUtil.getBundle(getClass());
或
Bundle bundle = Platform.getBundle("your plugin id");