項目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主要在項目構(gòu)建時使用,nature主要用來區(qū)分項目,項目的圖標(biāo)主要由第一個natures來決定,在plugin.xml文件對org.eclipse.core.resources.natures和org.eclipse.core.resources.builders擴展點進(jìn)行擴展后,可以通過如下方法將nature添加到項目中:(builder類似實現(xiàn),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"; //根據(jù)plugin.xml文件配置決定
System.arraycopy(onatures, 0, natures, 1, onatures.length);
description.setNatureIds(natures);
prj.setDescription(description, null);
return true;
}