Search code examples
javaeclipserefactoringpackagecopy-paste

Copy class + package-context between projects in Eclipse


For a number of uninteresting reasons: we need to copy many classes from one project to another (while preserving the package-structure of said classes).

In other words, given:

origin/src/com/foo/bar/A
origin/src/com/baz/qux/B

dest/ <empty>

We want to copy A and B such that we end up with:

dest/src/com/foo/bar/A
dest/src/com/baz/qux/B

Presently, we are forced to manually create the packages in dest and then Ctrl+C/Ctrl+V the individual .java files between projects. What we would like to do is to have Eclipse automatically copy the files over while automatically creating the packages (hence, preserving the package structure).


Solution

  • Presently, there is no clean pre-built solution for this. The answer is to write a script using any language of your choosing.

    This is exactly what I did: using Python.