tags:

views:

1885

answers:

5

I use eclipse to work on an application which was originally created independently of eclipse. As such, the application's directory structure is decidedly not eclipse-friendly.

I want to programmatically generate a project for the application. The .project and .classpath files are easy enough to figure out, and I've learned that projects are stored in the workspace under <workspace>/.metadata/.plugins/org.eclipse.core.resources/.projects

Unfortunately, some of the files under here (particularly .location) seem to be encoded in some kind of binary format. On a hunch I tried to deserialize it using ObjectInputStream - no dice. So it doesn't appear to be a serialized java object.

My question is: is there a way to generate these files automatically?

For the curious, the error I get trying to deserialize the .location file is the following:

java.io.StreamCorruptedException: java.io.StreamCorruptedException: invalid stream header: 40B18B81

Update: My goal here is to be able to replace the New Java Project wizard with a command-line script or program. The reason is the application in question is actually a very large J2EE/weblogic application, which I like to break down into a largish (nearly 20) collection of subprojects. Complicating matters, we use clearcase for SCM and create a new branch for every release. This means I need to recreate these projects for every development view (branch) I create. This happens often enough to automate.

+4  A: 

You should be able to accomplish this by writing a small Eclipse plugin. You could even extend it out to being a "headless" RCP app, and pass in the command line arguments you need.

The barebones code to create a project is:

IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("DesiredProjectName");
project.create(progressMonitor);
project.open(progressMonitor);

Just take a look at the eclipse code for the Import Project wizard to give you a better idea of where to go with it.

James Van Huis
Thanks, I'll give this a try
Kris Pruden
+1  A: 

Use AntEclipse

It can create eclipse projects from ant.

Tim Williscroft
A: 

I'm in the exact same boat James described. If he or anyone else has tried one or both of the suggestions I'm very interested in hearing about it.

Charlie
A: 

HI,

I have the same issue.. Can you specify how can I import an existing project into the workspace using command line script or ant???

Leela
A: 

I also have the exact same issue. I wish I could figure out how to programatically import projects into an Eclipse workspace. The original question was posed very well, except that it's not Eclipse projects that he's having trouble with - rather it's the Eclipse workspace.

Joseph Johnson