blob: 883bf662191284abd261e3c1d96283dfe72c14f0 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="Author" content="MAe">
<title>Moving and copying Java elements</title>
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
</head>
<body>
<h1>Moving and copying Java elements</h1>
<p> In this section, you will use refactoring to move a resource between Java packages.&nbsp;
Refactoring actions change the structure of your code without changing its
semantic behavior. </p>
<ol>
<li> In the Package Explorer view, select the <em>MyTestCase.java</em>
file from the <em>test</em> package and drag it into the <em>junit.samples</em> package.
Dragging and dropping the file is similar to selecting the file and
choosing <strong>Refactor &gt; Move </strong>from the context menu.
</li>
<li> 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 <strong>Preview </strong>button to see the list of changes that
will be made as a result of the move.
</li>
<li>
<p>Press <strong>OK</strong>. The file
is moved, and its package declaration changes to reflect the new location.</p>
<p> <img src="../images/qs-44.png" alt="File moved to junit.samples package">
</p>
</li>
<li><p>Use <strong>Edit &gt; Undo</strong> to undo the move.</p></li>
</ol>
<p>The context menu is an alternative to using drag and drop.&nbsp; 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.</p>
<ol>
<li>
Select the <em>MyTestCase.java</em> file and from its context menu, select <strong>Refactor
&gt; Move</strong>.</li>
<li> In the Move dialog, expand the hierarchy to browse the
possible new locations for the resource. Select the <em>junit.samples</em>
package, then click <strong>OK</strong>. The class is moved, and its
package declaration is updated to the new location.
<p> <img src="../images/qs-46.png" alt="Move destination dialog">
</p>
</li>
</ol>
<img src="../images/ngrelc.png" alt="Related concepts" border="0">
<p> <a href="../concepts/concepts-6.htm">Java views</a><br>
<a href="../concepts/concepts-9.htm">Refactoring support</a> </p>
<p> <img src="../images/ngrelt.png" alt="Related tasks" border="0">
</p>
<p> <a href="../tasks/tasks-80.htm">Refactoring</a><br>
<a href="../tasks/tasks-85.htm">Copying and moving Java elements</a><br>
<a href="../tasks/tasks-51.htm">Moving folders, packages and files</a> </p>
<p> <img src="../images/ngrelr.png" alt="Related reference" border="0">
</p>
<p> <a href="../reference/ref-menu-refactor.htm">Refactoring actions</a><br>
<a href="../reference/ref-117.htm">Refactoring wizard</a><br>
<a href="../reference/ref-13.htm">Java preferences</a> </p>
</body>
</html>