在插件开发中为现有的.project文件添加自然

时间:2014-07-30 04:44:46

标签: eclipse

我希望在将java项目转换为我自己的项目类型时,将我自己创建的插件的性质添加到java的.project。我可以这样做吗? 如果有人知道要作为样本编写的源代码,请给我。

非常感谢。

1 个答案:

答案 0 :(得分:1)

要向项目添加自然ID,您需要项目的IProject文件,并从中访问IProjectDescription

 IProject project = ... get project

 // TODO use project.hasNature("nature id") to check if already present

 IProjectDescription description = project.getDescription();

 String [] natures = description.getNatureIds();

 String [] newNatures = new String[natures.length + 1];

 System.arraycopy(natures, 0, newNatures, 0, natures.length);

 newNatures[natures.length] = "nature id";

 description.setNatureIds(newNatures);

 project.setDescription(description, null);
相关问题