使用Java将Java项目导入Eclipse

时间:2009-12-28 07:25:56

标签: java eclipse

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

2 个答案:

答案 0 :(得分:2)

here the same idea表示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;
}

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

答案 1 :(得分:1)

您可能需要编写Eclipse插件。

检查那些:

Eclipse Plugins Exposed

Eclipse Plugin Development - Tutorial (Eclipse 3.5)