Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a package name in Eclipse?

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?

like image 986
AndreaNobili Avatar asked Sep 24 '13 09:09

AndreaNobili


People also ask

Can you rename a package in Java?

If you are using Eclipse and all you want to do is first open the project that you want to copy(DON"T FORGET TO OPEN THE PROJECT THAT YOU NEED TO COPY), then clone(copy/paste) your Android project within the explorer package window on the left side of Eclipse. Eclipse will ask you for a new project name when you paste.

How do I find the package name in Eclipse?

Click on the root package and start typing the name of the package you are looking for. Show activity on this post. Ctrl + Shift + T works for packages too: Just type the package name and then a dot and it will show all classes in matching packages.

How do I rename a folder in Eclipse?

Right-mouse click in the repository view on the folder you want to rename and choose Rename path process. Rename the folder. Invoke "Add to Workspace". Perform synchronizing the Eclipse project folder and change will be reflected.


2 Answers

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
like image 51
Prabhakaran Ramaswamy Avatar answered Oct 19 '22 00:10

Prabhakaran Ramaswamy


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.

like image 35
Branislav Lazic Avatar answered Oct 18 '22 23:10

Branislav Lazic