How to change a package name in Eclipse?

204,387

Solution 1

First you need to create package:

com.myCompany.executabe (src > right click > new > package).

Follow these steps to move the Java files to your new package.

  1. Select the Java files
  2. Right click
  3. Refactor
  4. Move
  5. Select your preferred package

Solution 2

You can't rename default package since it actually doesn't even exist. All files in default package are actually in src folder.

src--
    |
    MyClass1.java <==== These files are in default package
    MyClass2.java
    |
    org
      |
      mypackage
              |
              MyClass3.java <=== class in org.mypackage package

Just create new package and move your classes within.

Solution 3

In pack explorer of eclipse> Single Click on the name of Package> click F2 keyboard key >type new name> click finish.

Eclipse will do the rest of job. It will rename old package name to new in code files also.

Solution 4

Android app package name?

Just for the record, my case concerned an android app so if it concerns renaming the package name in an android application, then you can do it directly from the AndroidManifest.xml file, it's the first field in the android manifest, you change your package name and update it. Then if it shows you errors, so just "clean" your project in the "project" menu.

Solution 5

  1. Select the classes you want to move to a different package name.
  2. Right click - Refactor - Move
  3. Create Package
Share:
204,387

Related videos on Youtube

AndreaNobili
Author by

AndreaNobili

Updated on July 05, 2022

Comments

  • AndreaNobili
    AndreaNobili almost 2 years

    In Eclipse I have a simple Java project that contains a package named (default package) and inside this package I have a class.

    I want to rename this package into something like: com.myCompany.executable

    I tried to select the (default package) ---> right click ---> refactor but now I see only the single voice named: Infer generic type arguments but not the possibility to change the package name.

    Why? What have I to do in Eclipse to change the name of the package?

  • Branislav Lazic
    Branislav Lazic over 10 years
    That won't work. You can't rename default package. Default package doesn't even exist.