13

I am trying to importing the project to eclipse through programmatically. I dont want to use UI mode.

Below is the code I used for importing the project:

IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(  new Path("PROJECT_PATH/.project"));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
project.create(description, null);
project.open(null);

I'm getting only the project folder along with .location file, .markers.snap file and .syncinfo.snap files, but I am not getting the source folder and etc.

2
  • Are you sure that the project that you are importing is already a java project? ie- is there a pre-existing .project file and does it have the java nature and java builder in it? Commented Sep 13, 2012 at 15:55
  • do you want to create a new project with its own set of files or do you want the workspace to point to the existing project? Commented Sep 14, 2012 at 18:50

3 Answers 3

13

Use org.eclipse.ui.wizards.datatransfer.ImportOperation

Try something like this:

IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
        public String queryOverwrite(String file) { return ALL; }
};

String baseDir = // location of files to import
ImportOperation importOperation = new ImportOperation(project.getFullPath(),
        new File(baseDir), FileSystemStructureProvider.INSTANCE, overwriteQuery);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());
Sign up to request clarification or add additional context in comments.

Comments

2

You're probably missing a line with

description.setLocation(new Path("/absolute/path/to/project/folder"));

1 Comment

Nice! It will set the local file path as the location for the described project instead of the default workspace's path.
0

Your code seems to be fine. What do you exactly mean by you couldn't get the source folder? Have you tried to refresh the project?

project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

2 Comments

Yes. Not getting the source folder
Well if you don't provide further source code (get source folder code), I won't be able to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.