How to change package name in Eclipse?

In Eclipse, I have a simple Java project that contains a package with the name (default package), and inside this package I have a class.

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

I tried to select (default package) ---> right click ---> refactoring, but now I see only one vote with the name: Infer generalized type arguments, but not the ability to change the package name.

What for? What do I need to do in Eclipse to change the package name?

+56
java eclipse refactoring
Sep 24 '13 at 9:15
source share
20 answers

First you need to create a package:

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

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

  • Select Java Files
  • Right click
  • Refactor
  • Move
  • Choose your preferred package.
+90
Sep 24 '13 at 9:22
source share

Press Alt+shift+R and change the package name

+2
Sep 24 '13 at 9:21
source share

You cannot rename the default package, as it does not even exist. All files in the package are located in the src folder by default.

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

Just create a new package and move your classes inside.

+1
Sep 24 '13 at 9:21
source share

create a new package, drag the class into it and now you can rename the new package

+1
Sep 24 '13 at 9:22
source share

In explorer eclipse> Single, click on the name of the package> press the keyboard key F2> enter a new name> click the end button.

Eclipse will do all the work. It will also rename the old package name to the new one in the code files.

+1
Aug 07 '14 at 11:06 on
source share

Android app package name?

For the record only, my case was about the Android application, so if it comes to renaming the package name in the Android application, you can do it directly from the AndroidManifest.xml file, this is the first field in the android manifest, you will change the name of your package and update it. Then, if it shows you errors, just β€œclean” your project in the β€œproject” menu.

+1
Dec 09 '14 at 17:10
source share

The AndroidManifest file has not changed for me, and I change the package name manually.

+1
May 2 '15 at 6:15
source share
  • Change the package name in the manifest.
  • A warning window will be said go to the workspace, click yes
  • then right click on src-> refactor -> rename paste your package name
  • select package name and subpackage name as

  • click "save" popup warning, click "continue"

name changed successfully

+1
Apr 28 '16 at 4:34
source share

Create a directory structure in the src folder, for example

.

means creating subpkg1 folder in pkg1 folder (source folder in eclipse), then put the source code inside and then change its package declaration.

0
Sep 24 '13 at 9:20
source share

Select all the files in the default package, right-click β†’ Refactoring ... β†’ Move .. and select the package in the dialog or create a new one.

0
Sep 24 '13 at 9:20
source share

Try creating a new package, and then move your files there.

Short overview: http://www.tutorialspoint.com/eclipse/eclipse_create_java_package.htm

0
Sep 24 '13 at 9:20
source share

Just create a new package and move the classes to the created package.

(default package) means it is not a package.

0
Sep 24 '13 at 9:20
source share

Just go to the class and replace the package statement with com.myCompany.executabe after this eclipse gives you options to rename the class to a new package and does the necessary

0
Sep 24 '13 at 9:21
source share
  • Select the classes you want to move to a different package name.
  • Right Click - Refactor - Move
  • Create package
0
Sep 24 '13 at 9:22
source share

com.myCompany.executabe is the path to the executable package. Here com, myCompany, the executable is three different packages. You need to manually rename the name of the individual package that you want to change.

0
24 Sep '13 at 9:46 on
source share

HOW TO BROWSE AND COPY AND PROGRAM ANDROID PROGRAMS

but. If you use Eclipse, and all you want to do is first open the project you want to copy (DON "T FORGET TO OPEN THE PROJECT YOU NEED TO COPY"), then clone (copy / paste) your Android project in the explorer package window on the left side of Eclipse. Then Eclipse will ask for a new project name when pasting. Give him a new project name. Since the name and directory of the Eclipse project are independent of the name and package of the application, the following steps will help you on how to change the package names. Note: There are two types of package names.

1.To change the package names of src packages in the Src folder, follow these steps: First you need to create a new package: (src β†’ β†’ right-click β†’ β†’ new β†’ β†’ package).

Example of creating a package: com.new.name

Follow these steps to move the Java files from the old copied package to part A to the new package.

Select Java files in this old package

Right click on this java file

select the option "Refactoring"

select the "Move" option

Select your preferred package from the package list in the dialog box. Most likely, you need to select the new one you just created and click "OK"

2.To change the name of the application package (main package), follow these steps:

First right click your project

Then go to the Android Tools section

Then select Rename Application Package

Enter a new name in the dialog box and click OK.

Then it will show you in which part of your project the application name will be changed.

It will show you that the application name will be changed in the manifest and in most relevant Java files. Click OK

YOU ARE DONE in this part, but make sure you rebuild your project so that it takes effect.

To rebuild your project, go to "project" β†’> "Clear" β†’ β†’ select a project from projects

and click OK. Finally, you can start your new project.

0
Jul 24 '14 at 20:07
source share

In Eclipse Kepler / 4.3 (and possibly in most other versions) you can:

A: rename the package in all files:

  • Select a project or any of its elements in Project Explorer
  • Menu: Search> File ... ()
  • In the "Contains text:" field, enter the name of the old package (for example, com.domain.oldpackage)
  • Replace ... ()
  • (Eclipse looks for project files for the old package name as a template)
  • In the "C:" field, enter a new package name (for example, com.domain.newpackage), OK
  • Proceed to confirmation if the preview does not show any conflict (which would probably mean that you need to clear something else before renaming the package)

B: Rename the src package:

  • Select the source package (e.g. Project> src and select com.domain.oldpackage) in Project Explorer
  • Menu: Refactoring> Rename ... ()
  • In the New Name: field, enter a new package name (for example, com.domain.newpackage)
  • Proceed to confirmation if the preview does not show any conflict (which would probably mean that you need to clear something else before renaming the package)

Note that in each of the Replace ... and Rename ... dialog boxes, all other default values ​​are left unless you selectively rename instances of the package name.

This procedure should automatically clean your project after the completion of each of A and B (including the gen / directory). But if you see any errors, you must manually clean and rebuild (and then select the project, OK) to restore the integrity of the project elements before continuing. And you must immediately test the project for this procedure to work before you make further changes and mix them.

0
Nov 14 '14 at 17:11
source share

Right click on your project
Android Tools β†’ Renaming an Application Package Just change the package there ... enter image description here

0
Jun 12 '17 at 7:29 on
source share

I tried this and fairly simple process:

Created a new package with the required name β†’ Moved all my classes to this new package (right-click on the previous package β†’ refractor β†’ Move )

0
Aug 29 '17 at 11:27
source share

enter a description of the image here You can open the class file in eclipse and add "XYZ package (package_name)) at the top and then show an error, click on it and select" move ABC.java (class_file) to XYZ package (package_name)

-one
Mar 18 '17 at 16:24
source share



All Articles