Search code examples
javaintellij-ideaintellij-14

IntelliJ how do I generate a new class?


When I go to my project structure and right click -> new, I only see new file/folder etc... but no class generation or packages. How do I get IntelliJ to do this? (I have Intellij 14 Ultimate - see image below)

intellij


Solution

  • IntelliJ will offer the option to create new class in the new menu, only if you right click within the part of your project structure, which is marked as Sources root or Test sources root.

    In your case, right click the src/main directory in the project structure view and select Mark directory As/Sources Root. That should fix it.


    Also, Gradle expects Java classes to be placed in src/main/java (and test Java classes in src/test/java) by default. I think that if you followed this convention, IntelliJ would mark those folders as (Test) Sources Root automatically. So maybe it would be better solution to adjust your project structure according to this convention.

    Here is a quote from Gradle guide regarding this issue:

    Gradle expects to find your production source code under src/main/java and your test source code under src/test/java