I'm using eclipse 3.8 indigo and I don't know why, when I'm creating a new package the destination of the new package goes outside. I want to create new packages within a package: package in package. I tried to copy / paste the newly created package or to move, but it just copies.
For example, I want to create different packages: dialogs, views, tables, etc. in my main source package. For example:
com.new.application // this is the the main package created by wizard
com.new.application.view // package that contains all views.
In reality there is no such thing as a sub-package in Java - each package is a completely separate entity, with the names being seemingly hierarchical only for convenience. For example, items with default visibility are not visible in sub-packages, despite what one might expect.
If your problem has more to do with presentation and aesthetics than substance, then perhaps what you are looking for is the hierarchical package presentation setting in the Eclipse Package Explorer: click on the little downward triangle/arrow at the top right of the package explorer and select "Hierarchical" in the "Package presentation" submenu:
This is a global setting and will affect all your opened/un-opened projects.
There is no concept of package with in package. Each package is separate namespace. I think if you go to folder view instead of package view, there you may see one under another.
The eclipse package explorer has two view options: flat or hierarchical. You are probably in the flat view (which is the default, who knows why). Change the view to hierarchical by clicking on the small triangle on the top right corner of the package view and then changing the package representation.
Firstly, you should select hierarchical representation.
Secondly, you should entitle completely package name. For example, you have 'main' package and you will create 'sub' package, you should entitle this with 'main.sub'. If you have just 1 package in package, may be you can't see hierarchicaly these packages.
After that, package view:
Second sub package creation:
Finally package view:
Related
I have a package where I'm putting all of my code.
However, I would now like to create a folder\package inside of that package like a child package.
I was unable to make a child package in eclise by folllowing the convention ExistingPackagename.ChildPackagename. So I went to my file system, made the desired structure. When I refresh, I see that my file system has the structure I want, but on eclipse, it still shows the Parent and the child packages at the same level. It shows my packages in the same level as
Parent
Parent.Child1
Parent.Child2
Parent.Child3
In reality there is no such thing as a sub-package in Java - each package is a completely separate entity, with the names being seemingly hierarchical only for convenience. For example, items with default visibility are not visible in sub-packages, despite what one might expect.
If your problem has more to do with presentation and aesthetics than substance, then perhaps what you are looking for is the hierarchical package presentation setting in the Eclipse Package Explorer: click on the little downward triangle/arrow at the top right of the package explorer and select "Hierarchical" in the "Package presentation" submenu:
You are probably in the "Project Explorer" view. Select Window -> Show view -> Package Explorer
Also, you don't have to create child packages from the file system. Just right click the current package, select New -> Package
I am moving a set of classes from one package structure to another.
Say I am moving the classes from com.oldstruct.oldpack to com.newstruct.newpack.
Is there any way to automatically change the package structure declaration for all the classes to the new package (com.newstruct.newpack) in Eclipse?
In package explorer right click on the package, choose refactor->rename type in com.newstruct.newpack.
In project explorer just drag and drop the classes from one package to another.Eclipse will automatically correct the package declarations for all those classes.You can also refactor and rename the package name .Refactoring will automatically update all the references.
My problem is very simple to describe.
I've made a Class named Car and I let IntelliJ build the Car.class file.
After that I've made another Project which has a dummy class called Main which wrapps this Car object.
In the project structure I've added as an external library the folder which contains Car.class.
So basicly after declaring the Car member variable in my Main dummy class, IntellJ normaly suggests me to import Car which is shown in the picture below.
Picture1
When I choose to import Car class it directly writes down the package before the Class name (not the usual import statement) and the import fails as shown on this picture.
Picture2
(note: the reason it states org.dino.test.pojos is because Car class package is org.dino.test.pojos)
The project setup is shown below.
Picture 3
Does someone know how to setup this project structure so such things work?
The fact that IntelliJ has marked the org directory as the library home is suspicious- I suspect that you have defined the classes in the library as the org subdirectory rather than the JAR or classes directory itself.
You also have a folder structure that is inconsistent with your package structure.
When you define the library, select the testLibrary directory/JAR rather than one of the directories inside it. Also, ensure that the folder structure inside your library matches the Java package of the class within it.
I'm developing an Android project which currently has 4 packages:
com.myapp.app.activities
com.myapp.app.db
com.myapp.app.ws
com.myapp.app.utils
Would I be able to create an additional package which is just
com.myapp.app
?
Eclipse isn't letting me create this package. It tells me a package with this name already exists.
If I start a new project and create a package called "com.testing.app" and then create a new package called "com.testing.app.activities" afterward, it works fine.
For Android developers:
What I'm wanting to do is extend the Application class and have it in a separate package. Suppose com.myapp.app can't be used, what's a good name for this new package?
Eclipse won't let you create this package because it already exists.
Packages in Java are represented in the filesystem as hierarchical folders: com.myapp.app.activities is in the com/myapp/app/activities folder. com/myapp/app already exists, so you can't create this package.
In Eclipse, juste create a new class, and in the "Package" section, precise you want to create it in the com.myapp.app package. This should work.
The package com.myapp.app already exists. You can create a class named com.myapp.app.MyClass, you'll see it right in the app package.
Another thing you can do is changing the layout of your packages from a flat layout to a hierarchical layout :
Resources :
help.eclipse.org : Project Explorer view
Eclipse by default hides empty packages. In the package explorer view, click at the small arrow in the right top: View Menu. Choose Customize View. In the Filters tab you need to uncheck Empty packages. Now empty packages will be visible in the package explorer.
It would appear that if I manually place a file into the directory and refresh the package explorer in Eclipse, the new com.myapp.app package appears
Using Netbeans, I want to put a package into another package. For example in Visual Studio 2008, I can have folder called "Nodes", and another folder inside of Nodes called "Expressions". How do I do this in Netbeans? I think a package in Java is equivalent to a folder in C#.
For a package within a package, put the parent name, a period, and then the name of the child's package like so: Nodes.Expressions.
It will appear as it's own separate package in an IDE perhaps, but the folder hierarchy will be as you desire: Nodes/Expressions/[classes etc]
You can create subpackages in java. If your package is called nodes, adding an expressions folder inside of it will create a nodes.expressions package.
FYI in Java, it is customary to use all lower case for package names.
Kevin is correct in his answer about packages.
Heres Netbeans specific steps for adding a new package:
In your Projects view, go to the parent package under "Source Packages".
Right click on the Package and select New>Java Package (if Java Package doesn't appear in the list, select Other... and then pick Java>Java Package)
Fill out the New Java Package wizard with name of the child package
You can have any number of subpackages, e.g. abc.def.ghi.jkl.
You can simply put the source in a folder within the current package structure. You reference it by adding a dot and the new package name to the end of the existing package name. In Netbeans, in the new file wizard, where the package name is referenced, you can input the new package by choosing an existing package and adding the .newpackagename to the end. Netbeans will then create the directory structure for you.