How to change a package name in Eclipse?
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.
- Select the Java files
- Right click
- Refactor
- Move
- 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
- Select the classes you want to move to a different package name.
- Right click - Refactor - Move
- Create Package
Related videos on Youtube
AndreaNobili
Updated on July 05, 2022Comments
-
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?
-
Balaji Dhanasekar over 10 yearsHave a look at this. stackoverflow.com/questions/10161840/…
-
-
Branislav Lazic over 10 yearsThat won't work. You can't rename default package. Default package doesn't even exist.