使用Java将Java项目导入Eclipse

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

你在这里有一个由Liran 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; } 

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

您可能需要编写Eclipse插件。

检查那些:

暴露的Eclipse插件

Eclipse插件开发 – 教程(Eclipse 3.5)