Maybe a stupid question but I have two packages in eclipse and now I would like to move the one package into the other for better structure.
Now I tried move but that generates a copy into the same package.
And with refactoring -> move I even can't select the packages
Can anyone help me....
thx all
If you have com.company.foo and com.company.bar, and want to move foo into bar, then just rename com.company.foo to com.company.bar.foo.
If you package happens to have subpackages, tick Rename subpackages to move the subpackages as well.
Use the package explorer view and rename the package. It asks for renaming updating references, renaming sub packages, update textual references in comments and and also non-Java text files. Click on the preview and then ok.
I have found the solution, when you rename a package to the desired destination, check on the box "rename subpackages" and there you go! :) – user1525788 Jul 10 at 9:14
if you have current package:
com.insect.fly
and would like to add subpackage to it, then renaming will solve the purpose e.g.
com.insect.fly.mosquitto
However, eclipse do not should it in nested style. Just do
Package Explorer > click on v button on the pane next to minimize > package presentation > Hierarchical
Hope that SOLVES !!
This is slightly non-intuitive, but the best way to do it is by right clicking on the package you wish to move, clicking on refactor, and then on rename.
Then proceed to enter the fully qualified path which you desire.
For example, if you wish that a package called dog be moved into a package called mammals which itself is in a package called animals you would essentially rename your dog package to animals.mammals.dog
In other words, the package structure
is represented as animals.mammals.dog in the world of Java packages, and a renaming achieves the desired effect.
Please note that you must not try to achieve this by manually moving the folders in Windows explorer. These actions are best done using your IDE.
this is rlly old but try opening in hierarchy mode. in project explorer click the small arrow (pointing down) > package presentation > hierarchical.
Related
I was experimenting with my eclipse setup trying to find a better way to browse through my projects packages and classes and I found the perfect view...then lost itðŸ˜.
I've tried every view but I can't get it back. It was like package explorer but it appeared above the code editor and it contained separate views for projects, packages, and classes. You could click on the leftmost box containing the project, then the middle box would populate with the packages within, then you could click on the package and the right most box would populate with the classes within.
My best guess is it's a way to customize the project explorer or package explorer but I can't seem to figure it out.
I want to say when I found it I was experimenting with working sets but I could be wrong.
Thanks for any help in advance!
I have recently started coding on Eclipse for Minecraft Bukkit plugins, and I have been going fine with it. Recently, I've been trying to make a child package into a package, but if I try New > Package, then it makes a package separate to my main package. I am a beginner, so please make instructions simple. Is there anything else I can try?
Normally, if you separate each package component with dots (.), it should create intermediate entries.
Try create a new package with the following test case:
com.foobar.example
com.foobar.test
com.foobar.example.a
And Eclipse should do the tricks.
If however, you are stuck with finding those empty packages, perhaps you should simply play with the Package Explorer options: the Java filters is especially useful, and there might be an option enabled by default which would filter/hide empty package.
You also have Package presentations.
Since an image is better than long lines of text:
Click the arrow to open the presentations options (see the Package Explorer on the left)
The Filters options does have filters which might hide empty parent packages.
The hierarchical package presentation behave like the Explorer left pane.
When creating a new package you can create a hierarchy by simply separating your parent folder with child folder with a dot '.'. So if you want to create a sub package of foo.bar you have to create a package with name foo.bar.myfoo. Eclipse will do the rest.
If you instead want to visualize the folder type hierachy as here:
you can click in the little arrow top left of the project explorer view menù and go to Package Presentation > Hierarchical.
A folder-like hierachy is implicitly created by the package names in Java. Lets say you have a package com.company and you want a sub-package in that package. Then you have to create a package with the name com.company.product. It is not done by creating a package with the name product while com.company is selected!
For eclipse Version: 2019-03 (4.11.0) Build id: 20190314-1200
I found it easier to create the desired package path along with the new class I wanted to exist at the new package path.
From within the Project Explorer view, right click on the corresponding project to create a New Class.
Then on the class creation popup I fill in the corresponding package field as I please to build out the new path as desired, along with the new class to sit in that new path.
For Eclipse Version 2020-09:
To create sub-package we can directly go inside the eclipse-workspace and in the package where we want to create a sub-package and inside that we can create a new folder and then click on the three dots icon on the right side of the Package Explorer and select the Hierarchical option inside the package presentation option. We can then refresh the project and the new sub-packages will be reflected.Below is the image for reference
Subpackage
In eclipse when I control click or select an object an hit "F3", I get directed to a class in a jar instead of the package in eclipse.
Of course the jar content has the same class as the package in eclipse but I don't want it to search there.
How can I fix the folders for the so called "Open Declaration"?
Thank you in advance.
Ok, so a colleague of mine found the answer, attached you can see a picture of the packages "Order and Export". The "JBoss 4.2 ..." was on 2nd place from the top and the actual package where he should have searched (top arrow) was almost on the bottom. I changed the ordering as pictured, now it works perfect.
Assuming that the import from your project corresponding to this class is the right one, and that you chose a package name different from the one used in the jar file :
Rename your class, or suppress the ambiguity by prefixing your class name by the package name in your code. Right now, I don't see any other option.
org.test.MyClass c = new org.test.MyClass();
How can I make a child package inside a package in eclipse project explorer?
I already tried..
com.proj.test
then I create a new package
com.proj.test.child
to add a child package at package
com.proj.test,
but did not succeed
To enable hierarchical visualization in the eclipse package explorer do these following steps:
In The Package Explorer View / View Menu (An arrow pointing down on top right) Go to Package Presentation and set type to Hierarchical.
What you did is correct, I assume you are using 'Project explorer' view, switch to hierarchical view to see content as child-parent : Window->Show View->Navigator
Right click on the package com.proj.test, new -> package and then write com.proj.test.child for the name.
I tried it just now and it works well.
When you select "New Package" off the eclipse menu, the corresponding folder(s) will also be created automatically.
You don't have to define sub-packages one level at a time.
If You define a new package and enter the package name
com.coder.javapackage.innerone.etc
any missing elements in that package tree will also be created automatically.
This is just visual representation on the package. In reality they can sit in two different jars, but you should not be concerned about it, because jvm and loader internally handle that.
I gave up on trying to reason with Eclipse as it seemed to completely ignore my hierarchal package representation setting, plus it was ignoring packages for some reason and refusing to compile as a result… I just made the folder hierarchy myself in Finder then imported it into Eclipse. That fixed everything.
In Project Explorer perspective View Menu -> Package Presentation -> Hierarchical . I hope it helps.
I was able to change the "Package Presentation" option, which by default has the option "Flat" to "Hierarchical". This option is present in button "View menu", on "Project Explorer" perspective.
First create the parent package and then press the right click on the parent package select new package where you see new window will appear then write new package name beside the parent package with dot.
Ex- test (this is parent package called test)
test.model (this is child package called model)
like this you can on and on to make more package like - test.model.modelOne
Hope this will help someone.
Right click on package parent and write complete name of child package is OK. But then to have a good graphical representation, you have to add a file in this child package... It's just refresh IHM (if you look folders of project, they already exist before this refresh). Eclipse does not refresh enough project window...
If your project under "Project explorer" view then change it to "Navigator" .
As follows
Window->Show View->Navigator
By doing this you will able to see packages as parent child hierarchy.
What I want to do is simply use the eclipse package explorer in hierarchical view but with empty packages being collapsed so I don't have to open 5+ packages to find the first Java file.
I'm not even sure how I did it in previous versions, but I've never had any trouble finding it before, it just seems to be gone now. I have a feeling there was a "flatten hierarchy" tick-box somewhere.
To clarify I get this:
com
example
etc
file1.java
Rather than:
com.example.etc
file1.java
I'm using Eclipse Indigo (v. 3.7.1)
Open the View menu (small triangle in top right corner), open filters and check Empty parent packages.
In most cases it works, but in case of existing projects it does not always work as expected. If you seem to have troubles, try to export the project, remove it, then re-add the exported version (or re-checkout from your VCS).
Assuming the view filter is engaged properly, perhaps your source folders are not as "empty" as you think.
For example, on Apple OS X, Eclipse will detect .DS_STORE entires along your src/package/hierarchy, making the parent packages technically non-empty.
Delete any such hidden files and refresh your project.
Window - Preferences - Java - Appearance - Abbreviate package names
And enter the following rule:
com.example.etc={cee}
I don't know what the problem actually was, but I couldn't get it fixed until I gave up altogether and reinstalled the OS (it was a fresh install anyway), and eclipse. It was completely fine after that. :\
Click on the arrow at the top right of the "Package explorer" and choose "Package presentation -> flat"
Try to restart Eclipse once in a while. I had trouble getting it to work, and after an Eclipse restart it suddenly was working again.