IntelliJ how do I create a new class?

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

intellij

+7
java intellij-idea intellij-14
source share
2 answers

IntelliJ will offer the opportunity to create a new class in the new menu only if you right-click inside the part of the project structure that is marked as the root directory of sources or source roots.

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


In addition, Gradle expects Java classes to be placed in src/main/java (and check Java classes in src/test/java ) by default. I think that if you followed this convention, IntelliJ would automatically label these folders as (Test) Sources Root. Therefore, perhaps it would be the best solution to customize the project structure in accordance with this agreement.

Here is a quote from the Gradle guide regarding this issue:

Gradle expects to find the source code of your production in src / main / java and your test source code in src / test / java

+9
source share

This will help you create a class, interface or annotations in IntelliJ

https://www.jetbrains.com/idea/help/creating-java-classes-interfaces-enumerations-and-annotations.html

0
source share

All Articles