Create new package in IntelliJ

JavaIntellij Idea

Java Problem Overview


I've just moved from years of using Eclipse to the brave new world of IntelliJ and I'm trying to iron out the little (trivial) little things that are slowing me down.

The latest is hopefully painfully obvious when you know how to do it.

I create a new package under my source folder:

uk.ac.cam.admin

I right click on this new package to create another sub-package:

uk.ac.cam.admin.domain

All well so far, now I want to create a package of service at the same level as domain. However creating it from uk.ac.cam.admin.domain quite rightly results in uk.ac.cam.admin.domain.service and creating it on the source just results in service.

Obviously I can create a new package from the source and type the fully qualified path, but it's 2013 and I'm lazy! ;)

Java Solutions


Solution 1 - Java

Disable Compact Empty Middle Packages option in the Project View:

compact

You will now see admin as a separate node and will be able to create a new package inside it.

Solution 2 - Java

You can follow these steps:

  1. Select the package from Project Pane

  2. Double click the relevant section from the breadcrumb. Then it will get selected.

  3. Right click on the same item

  4. Select "New" → "Package" from the menu

enter image description here

Solution 3 - Java

Follow these steps:

  1. First set the folder as a "Sources Root" by right clicking and navigating to "Mark directory".

  2. Right click on the same item

  3. Select "New" → "Package"

In my case, I was not able to see the create new package option.

Solution 4 - Java

To create package the Folder/Directory should be marked as Source or Test. Right click project->Project Structure->Project settings->Modules->select the folder where you want to create package and mark its as either Source or Test by clicking the respective colored icons. Then apply and ok. Now you will see the Folder either in blue(Source) or green(Test)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStuPointerExceptionView Question on Stackoverflow
Solution 1 - JavaCrazyCoderView Answer on Stackoverflow
Solution 2 - JavaTharakaView Answer on Stackoverflow
Solution 3 - JavaVaibhav DesaiView Answer on Stackoverflow
Solution 4 - JavaRamesh ThoutamView Answer on Stackoverflow