在 Eclipse 中更新项目文件
Update project file in Eclipse
我用这个库
org.eclipse.core.resources
我正在尝试更改项目文件中的项目名称以匹配项目的实际名称。我从 SVN 存储库导入了一个项目,然后用新名称重命名了包含该项目的文件夹,但是如果我刷新工作区,项目文件中的名称不会改变。即使我特意告诉他:
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(targetProject.replace("\", "/") + "/.project"));
description.setName(targetProject.substring(targetProject.lastIndexOf("com."))); // here the name in description is changed
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); // a get project from the actual description name that match with the folder name
if (!project.exists()) {
project.create(description, monitor);
}
if (!project.isOpen()) {
project.open(monitor);
}
project.setDescription(description, monitor); // force the name in project to change
project.refreshLocal(IProject.DEPTH_INFINITE, monitor); // refresh project in case that matter
// Check change
System.out.println(project.getDescription().equals(descritpion)); // false !
System.out.println(project.getDescription().getName().equals(description.getName())); // false !
这个名字好像什么也改变不了。工作区中的名称是新名称。我也尝试关闭并再次打开该项目,但没有任何反应。
这段代码有什么问题?任何帮助将不胜感激。
谢谢。
IProjectDescription.setName
的 JavaDoc 说:
Setting the name on a description and then setting the description on
the project has no effect; the new name is ignored.
Creating a new project with a description name which doesn't match the
project handle name results in the description name being ignored; the
project will be created using the name in the handle.
所以你不能这样做。
我知道怎么做了:
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(targetProject.replace("\", "/") + "/.project"));
description.setName(targetProject.substring(targetProject.lastIndexOf("com.")));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
if (!project.exists()) {
project.create(description, monitor);
}
if (!project.isOpen()) {
project.open(monitor);
}
project.move(description, IProject.DEPTH_ONE, monitor); // This change name
感谢您的帮助。
我用这个库
org.eclipse.core.resources我正在尝试更改项目文件中的项目名称以匹配项目的实际名称。我从 SVN 存储库导入了一个项目,然后用新名称重命名了包含该项目的文件夹,但是如果我刷新工作区,项目文件中的名称不会改变。即使我特意告诉他:
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(targetProject.replace("\", "/") + "/.project"));
description.setName(targetProject.substring(targetProject.lastIndexOf("com."))); // here the name in description is changed
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); // a get project from the actual description name that match with the folder name
if (!project.exists()) {
project.create(description, monitor);
}
if (!project.isOpen()) {
project.open(monitor);
}
project.setDescription(description, monitor); // force the name in project to change
project.refreshLocal(IProject.DEPTH_INFINITE, monitor); // refresh project in case that matter
// Check change
System.out.println(project.getDescription().equals(descritpion)); // false !
System.out.println(project.getDescription().getName().equals(description.getName())); // false !
这个名字好像什么也改变不了。工作区中的名称是新名称。我也尝试关闭并再次打开该项目,但没有任何反应。
这段代码有什么问题?任何帮助将不胜感激。
谢谢。
IProjectDescription.setName
的 JavaDoc 说:
Setting the name on a description and then setting the description on the project has no effect; the new name is ignored.
Creating a new project with a description name which doesn't match the project handle name results in the description name being ignored; the project will be created using the name in the handle.
所以你不能这样做。
我知道怎么做了:
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(targetProject.replace("\", "/") + "/.project"));
description.setName(targetProject.substring(targetProject.lastIndexOf("com.")));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
if (!project.exists()) {
project.create(description, monitor);
}
if (!project.isOpen()) {
project.open(monitor);
}
project.move(description, IProject.DEPTH_ONE, monitor); // This change name
感谢您的帮助。