Moving elements

NetBeans enables the developer to easily move classes around different projects and packages.

No more breaking compatibility when moving those classes around, since all are seamlessly handled by the IDE.

Getting ready

For this recipe we will need a Java project and a Java class so we can exemplify how moving elements really work.

The exisiting code, created in the previous recipe, is going to be enough. Also you can try doing this with your own code since moving classes are not such a complicated step that can't be undone.

Let's create a project:

  1. Create a new project, which can be achieved either by clicking File and then New Project or pressing Ctrl+Shift+N.
  2. In the New Project window, choose Java on the Categories side and Java Application on the Projects side, then click Next.
  3. Under Name and Location, name the Project as MovingElements and click Finish.
  4. Now right-click on the movingelements package, select New... and Java Class....
  5. On the New Java Class dialog enter the class name as Person.
  6. Leave all the other fields with their default values and click Finish.

How to do it...

  1. Place the cursor inside of Person.java and press Ctrl+M.
  2. Select a working project from Project field.
  3. Select Source Packages in the Location field.
  4. Under the To Package field enter: classextraction:
How to do it...

How it works...

When clicking the Refactor button the class is removed from the current project and placed in the project that was selected from the dialog.

The package in that class is then updated to match.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.112.217