Eclipse plugin 在Eclipse插件中的自定义项目中添加自然属性失败

Eclipse plugin 在Eclipse插件中的自定义项目中添加自然属性失败,eclipse-plugin,Eclipse Plugin,我正在开发一个插件来实现一个带有自定义性质和生成器的自定义项目类型。在新向导中,我执行以下代码来创建项目: IProject newProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(projectName); IProjectDescription desc = newProject.getWorkspace() .newPr

我正在开发一个插件来实现一个带有自定义性质和生成器的自定义项目类型。在新向导中,我执行以下代码来创建项目:

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) { (...) }
现在项目已经创建,我尝试使用以下代码添加nature:

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
所有这些代码都部分工作,因为项目实际上已创建,但其中没有.project文件。我看不出有什么错误

我做错了什么?如何调试问题

谢谢你的帮助。
Thierry

我认为这可能是因为您在项目描述中设置了项目位置。而不是

desc.setLocationURI(projectLocation);
召唤

desc.setLocation(空);
仅当描述中的位置不是默认位置时,才应设置该位置