gpt4 book ai didi

java - 使用 Java 将 Java 项目导入 Eclipse

转载 作者:行者123 更新时间:2023-12-04 07:00:22 28 4
gpt4 key购买 nike

我写了一个java程序来编写另一个java项目。但是,我想添加一段将项目导入工作区的特定代码。这能做到吗?

最佳答案

您有 here the same ideaLiran Orevi 表示但有更多细节和代码示例:

/**
* Imports the given path into the workspace as a project. Returns true if the
* operation succeeded, false if it failed to import due to an overlap.
*
* @param projectPath
* @return
* @throws CoreException if operation fails catastrophically
*/
private boolean importExisitingProject(IPath projectPath) throws CoreException {
// Load the project description file
final IProjectDescription description = workspace.loadProjectDescription(
projectPath.append(IPath.SEPARATOR + IProjectDescription.DESCRIPTION_FILE_NAME));
final IProject project = workspace.getRoot().getProject(description.getName());

// Only import the project if it doesn't appear to already exist. If it looks like it
// exists, tell the user about it.
if (project.exists()) {
System.err.println(SKTBuildPlugin.getFormattedMessage(
"Build.commandLine.projectExists", //$NON-NLS-1$
project.getName()));
return false;
}
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.create(description, monitor);
project.open(IResource.NONE, monitor);
}
};
workspace.run(runnable,
workspace.getRuleFactory().modifyRule(workspace.getRoot()),
IResource.NONE, null);
return true;
}

this thread ,您还可以导入压缩的项目,其中一些代码的灵感主要来自 org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage.java .

关于java - 使用 Java 将 Java 项目导入 Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1968369/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com