开发者

Import Java project into Eclipse using Java

I've written a java program that writes another java project. However, I want to add a piece of speci开发者_运维知识库fic code that will import the project into the workspace. Can this be done?


You have here the same idea expressed by Liran Orevi but with some more details and a code example:

/**
* 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;
}

In this thread, you can also import projects which are zipped, with some code inspired from mostly scraped from org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage.java.


You'll probably need to write an Eclipse Plugin.

Check those:

Eclipse Plugins Exposed

Eclipse Plugin Development - Tutorial (Eclipse 3.5)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜