tags:

views:

599

answers:

2

In Eclipse how do I copy the Java Build Path to a different workspace?

Somebody somewhere wrote that if you copy the project then you have copied the build path also. This doesn't seem to be the case.

I've tried copying the entire workspace to a new directory. Opening Eclipse and pointing it to the new directory has all the projects and source files but the build path for my project is empty. It doesn't even have the basic Java source files to build against (java.lang.Object).

Eclipse 3.3.0 (Europa)

Any ideas?

A: 

The build path is stored in a file named .classpath in the project's root directory. I don't know of any different way, and copying the directory should also copy that file, of course. How do you copy the project? What OS?

Michael Borgwardt
Debian linux is the OS. I was copying by doing a cp -R on the file system. I've tracked down the .classpath file and it looks like the one I was copying was not set up correctly. I'll try again later. Thanks.
+1  A: 

Be very careful...

The workspace itself is just metadata in eclipse that points to your project folders. If the projects are not actually in the workspace directory, you aren't actually copying them, just references to them.

This can happen if you use "Import existing projects into workspace" that are folders in the file system without the "copy into workspace" checkbox checked, or if you create a project using an existing directory.

If you copy that workspace to a different machine, the projecs won't be there.

If you want to share projects, your best bet would be to use source/version control (subversion, for example) and have everyone hook up to the same repository.

Another note on the build paths -- if you have a java project reference an external jar, the absolute path of that jar is stored in the build path. This can be bad if other people who are sharing that project have the jar in a different location on their machine. If this happens, you should look into using Classpath variables or user libraries in eclipse.

Can you comment more on what you're attempting to do when you do the copy?

Scott Stanchfield
I want to have two versions of the source code - one for current development and one for the current production code.It was a problem with the .classpath file. I corrected that and everything works as I want it now. Thanks for your help.
Oh -- better approach: use source version control like subversion and create a branch. You can then simply check the code out in two workspaces from the two branches. This also allows fairly simple merging of changes from on branch to another.
Scott Stanchfield