项目nature和builder都会在.project文件中看到,如下:
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
builder主要在项目构建时使用,nature主要用来区分项目,项目的图标主要由第一个natures来决定,在plugin.xml文件对org.eclipse.core.resources.natures和org.eclipse.core.resources.builders扩展点进行扩展后,可以通过如下方法将nature添加到项目中:(builder类似实现,api查看IProjectDescription)
private static boolean addNature(IProject prj) throws Exception {
IProjectDescription description = prj.getDescription();
String onatures[] = description.getNatureIds();
String[] natures = new String[onatures.length + 1];
natures[0] = "cn.aaa.bbb.natures"; //根据plugin.xml文件配置决定
System.arraycopy(onatures, 0, natures, 1, onatures.length);
description.setNatureIds(natures);
prj.setDescription(description, null);
return true;
}