I have a bunch of packages in an Eclipse project they have names like:
edu.xxx.proj.app
edu.xxx.proj.demo
edu.xxx.proj.utils
Is there a way in Eclipse to automatically collapse them into a folder structure? I would like them to be as follows on the workbench:
edu__
|_xxx__
|_proj__
|_app
|_demo
|_utils
Click the little down pointing triangle in the package manager and go to "package presentation". From there select "hierarchal" and that should take care of it.
Related
i got this sample solution from my Professor, but somehow it isn't working.
IntelliJ does not recognize the packages. That's the case for every class.
When I hover over it it says:
"Package name 'spaceman.view.util' does not correspond to the file path 'view.util' "
Has anyone any idea what could be wrong?
I'm a total beginner when it comes to coding so sorry, if the question is banal.
Thank you!!
Your project spaceman is the sources root. That means anything inside a folder view/welcome in that folder is supposed to be in the package view.welcome. If you want to keep the package spaceman.view.welcome then move the whole tree into another folder spaceman inside your spaceman project directory.
Note that it's rather unusual to have the project root itself be the source root. It's way more common to have a directory like src/ be the source root (or, if you follow the Maven/Gradle convention something like src/main/java).
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
My package name does not contain my full folder structure.
For instance - in IntelliJ I have created a test class:
and its package was initialized with package com;
How do I set which is the starting folder for the package name?
What is the difference between blue and yellow/gold folder color in the IntelliJ project window?
How do I set which isw the starting folder for the package name
File -> Project Structure. On the left, select Modules.
In the rightmost window, you will have a tab named "Sources". There you will have the opportunity to change your source/test directories. Note that a directory must exist before it is selectable this way.
Although I wouldn't depart from the setup you currently have, it's pretty standard.
What is the difference between blue and yellow/gold folder color in intelliJ project window
You will see that in the tab above ;)
We're creating a new project in IntelliJ and must have something wrong because when we right click on a directory, select New and then get the context menu, Java based options are not shown. Currently get things like File, some HTML options, XML options.
We have assumed so far it's something we haven't configured correctly in the Project/Module configuration. The new module we are talking about is part of a multi module project. We created it using a Maven web archetype.
Any help configuring the project nature?
Edit: The answer is basic: 'That moment when you realise somethings not working because you haven't been clicking 'Apply'... :) We had a good laugh at ourselves when we discovered this'
The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).
If this is not the case, right click your root source directory -> Mark As -> Source Root.
This can also happen if your package name is invalid.
For example, if your "package" is com.my-company (which is not a valid Java package name due to the dash), IntelliJ will prevent you from creating a Java Class in that package.
you need to mark your directory as source root (right click on the parent directory)
and then compile the plugin (it is important )
as result you will be able to add classes and more
If you open your module settings (F4) you can nominate which paths contain 'source'. Intellij will then mark these directories in blue and allow you to add classes etc.
In a similar fashion you can highlight test directories for unit tests.
Project Structure->Modules->{Your Module}->Sources->{Click the folder named java in src/main}->click the blue button which img is a blue folder,then you should see the right box contains new item(Source Folders).All be done;
I will share another interesting point. If you try to create a package with the reserved keyword then it will be treated as a normal directory and not a package. I was having this issue where I was creating a package named import and it was converting that to a directory.
Another possible solution is that the project name is not acceptable. For example, creating a project with spaces in the name does not block the project creation but the proper sources are not marked and when those are marked manually, I still was unable to create classes. Recreating the project with hyphens (-) instead of spaces corrected the problem for me.
Make sure you are not creating a package name which is same as predefined keywords in java like enum, int, long etc.
In my case I was trying to create a class under "enum" package. As soon as I changed package name to "enums" I was able to create class in it.
Had this issue too. Invalidating Caches/Restart did the trick for me. Please upvote so the the IntelliJ folks take this more seriously. This gives the IDE a terrible UI/UX experience.
https://youtrack.jetbrains.com/issue/IDEA-203100
There is another case where 'Java Class' don't show, maybe some reserved words exist in the package name, for example:
com.liuyong.package.case
com.liuyong.import.package
It's the same reason as #kuporific 's answer: the package name is invalid.
If you just created your project, let IntelliJ finish indexing your project.
You need to mark your java directory as Source Root ,
Right Click on Java directory
Select Mark Directory as option and click on the sub menu option Source Root
Most of the people already gave the answer but this one is just for making someone's life easier.
TL;DR
You must add the test folder as source.
Right click on java directory under test
Mark it as Tests
Add src/test/java in Test Source Folders
Thats it, IntelliJ will consider them as test source.
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