在创建项目时,有时需要定制项目属性
[code]public static void addProjectNature(IProject project, String nature,
IProgressMonitor monitor) throws CoreException {
if (project != null && nature != null) {
if (!project.hasNature(nature)) {
IProjectDescription desc = project.getDescription();
String[] oldNatures = desc.getNatureIds();
String[] newNatures = new String[oldNatures.length + 1];
newNatures[0] = nature;
if (oldNatures.length > 0) {
System.arraycopy(oldNatures, 0, newNatures, 1,
oldNatures.length);
}
desc.setNatureIds(newNatures);
project.setDescription(desc, monitor);
}
}
}[/code]
使用例子:
***Util.addProjectNature(project, New_NATURE, null);
[code]public static void addProjectNature(IProject project, String nature,
IProgressMonitor monitor) throws CoreException {
if (project != null && nature != null) {
if (!project.hasNature(nature)) {
IProjectDescription desc = project.getDescription();
String[] oldNatures = desc.getNatureIds();
String[] newNatures = new String[oldNatures.length + 1];
newNatures[0] = nature;
if (oldNatures.length > 0) {
System.arraycopy(oldNatures, 0, newNatures, 1,
oldNatures.length);
}
desc.setNatureIds(newNatures);
project.setDescription(desc, monitor);
}
}
}[/code]
使用例子:
***Util.addProjectNature(project, New_NATURE, null);