Moving & Copying Java Elements

In this section, you will create a new package and classes and move resources between Java packages.

1.

In the Packages view, select the MyTestCase.java file and drag it into to the junit.framework package. The class is moved, and its declaration changes to reflect its new location.

2.

Select the MyTestCase.java file and drag it into to the root directory of the JUnit project. A default package is created to contain the class, and the package declaration is removed to reflect its new location.

3.

Select the MyTestCase.java file and from its context menu, select Move. In the Move dialog, expand the hierarchy to browse the possible new locations for the resource.

Using the context menu option is simply an alternative to dragging and dropping.

Select the junit.framework package, then click OK. The class is moved, and the package declaration changes to reflect its new location.

Note: This example did not result in compile errors. However, moving a compilation unit can lead to compile errors because import statements are not updated with a compilation unit is moved.