0
我正在開發一個插件來實現具有自定義特性和構建器的自定義項目類型。在一個新的嚮導,我執行下面的代碼來創建項目:在Eclipse插件的自定義項目中添加一個特性失敗
IProject newProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
IProjectDescription desc = newProject.getWorkspace()
.newProjectDescription(newProject.getName());
desc.setLocationURI(projectLocation);
try {
newProject.create(desc, null);
if (!newProject.isOpen()) {
newProject.open(null);
}
} catch (CoreException e) { (...) }
現在創建項目,我嘗試用下面的代碼添加性質:
if (!project.hasNature(MyNature.NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = MyNature.NATURE_ID;
description.setNatureIds(newNatures);
IProgressMonitor monitor = new NullProgressMonitor();
project.setDescription(description, monitor);
}
這裏是內容我的plugin.xml文件:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Eclipse
Bundle-SymbolicName: com.myapp.eclipse;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.myapp.eclipse.Activator
Bundle-Vendor: MyApp
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.6.1",
org.eclipse.ui.ide;bundle-version="3.6.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: com.myapp.eclipse,
com.myapp.eclipse.builder,
com.myapp.eclipse.nature,
com.myapp.eclipse.saving
所有這些代碼部分工作,因爲這個項目實際上是創建但在它沒有項目文件。我看不到任何錯誤。
我做錯了什麼,我該如何調試問題?
感謝您的幫助。 Thierry