Import Java project into Eclipse using Java

前端 未结 2 477
北恋
北恋 2021-01-15 10:37

I\'ve written a java program that writes another java project. However, I want to add a piece of specific code that will import the project into the workspace. Can this be

相关标签:
2条回答
  • 2021-01-15 11:19

    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.

    0 讨论(0)
  • 2021-01-15 11:29

    You'll probably need to write an Eclipse Plugin.

    Check those:

    Eclipse Plugins Exposed

    Eclipse Plugin Development - Tutorial (Eclipse 3.5)

    0 讨论(0)
提交回复
热议问题