Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 561
Ryan Delucchi Avatar asked Jul 06 '12 22:07

Ryan Delucchi


People also ask

How do I copy and paste a package in Eclipse?

Select the package in the project explorer, press Ctrl+C and then Ctrl+V, Eclipse will prompt with a package name conflict warning and ask you to enter a new package name. Just enter it and Eclipse will repackage all copied classes accordingly.

What is the difference between package and project in Eclipse?

An Eclipse project has nothing to do with Java. It is a feature of Eclipse to organize and configure your different projects. A Java package is a language feature of Java. You can use them to structure your project and control visibility between different classes.


1 Answers

You can just copy the files between your project folders using a shell script. Eclipse will pick up the copied java files including the package structure.

If you select all the files in the source project in Navigator Window panel (not Package Explorer) you should be able to CTRL+C/V the whole file structure preserving packages to a new project.

like image 99
maestr0 Avatar answered Sep 22 '22 04:09

maestr0