Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Eclipse Java Development User Guide
Previous Page Home Next Page

Moving and copying Java elements

In this section, you will use refactoring to move a resource between Java packages.  Refactoring actions change the structure of your code without changing its semantic behavior.

  1. In the Package Explorer view, select the file from the test package and drag it into the junit.samples package. Dragging and dropping the file is similar to selecting the file and choosing Refactor > Move from the context menu.
  2. You will be prompted to select whether or not to update references to the file you are moving. Typically, you will want to do this to avoid compile errors. You can press the Preview button to see the list of changes that will be made as a result of the move.
  3. Press OK. The file is moved, and its package declaration changes to reflect the new location.

    File moved to junit.samples package

  4. Use Edit > Undo Move to undo the move.

The context menu is an alternative to using drag and drop.  When using the menu, you must specify a target package in the Move dialog, in addition to selecting the update references options you've already seen.

  1. Select the file and from its context menu, select Refactor > Move.
  2. In the Move dialog, expand the hierarchy to browse the possible new locations for the resource. Select the junit.samples package, then click OK. The class is moved, and its package declaration is updated to the new location.

    Move destination dialog

Related concepts

Java views
Refactoring support

Related reference

Refactoring actions
Refactoring wizard
Java preferences

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire