After creating a new directory in the project, to add a Java class file to the directory, right-click New finds no corresponding option.
Cause: After creating the directory, you need to set the directory role so that idea can be identified.
Method: File-project Structure
The following are explained for several directory types:
Sources
: Generally used for labeling similar src
to such a compiled directory. Sometimes we don't just have src
to compile the directory of the project, there are some other special directories that we might want to use as a compiled directory, and we need to label that directory. This Sources
is the only kind of compiled catalog that can create new Java classes and packages, which you need to keep in mind.
Tests
: Typically used to label a compiled unit test catalog. In the canonical MAVEN project structure, the top-level directory is src
, maven src
We are not set to Sources
, but in its subdirectory directory under the directory main
java
we will set as Sources
. The directory where the unit tests are, we set the directory as a src - test - java
java
Tests
compiled unit test directory. Generally this and the next few of us are configured under the MAVEN project, but I'll talk about it first. From this we can also see that IntelliJ idea's support for the MAVEN project is more than thorough.
Resources
: typically used to label resource file directories. Under the MAVEN project, the resource directory is separate, and its directory is: src - main -resources
, here's the resources
directory we will set to Resources
, indicating that the directory is as a resource directory. The files under the resource directory are compiled into the output directory.
Test Resources :
A directory of resource files typically used for labeling unit tests. Under the MAVEN project, the Resource directory for unit tests is separate, and the directory is: here we set the directory as the src - test -resources
resources
Test Resources
Resource directory for unit tests. The files under the resource directory are compiled into the output directory.
Excluded
: Generally used to label exclude directories. Excluded directories are not indexed by IntelliJ idea, which is equivalent to being discarded by IntelliJ idea, which is a code file that does not have regular code features such as code checking and smart hints.
With the above introduction, we know that for non-MAVEN projects we just have to set it up src
.
The annotated directory will have a general summary on the right. classes
Although it is a Excluded
directory, but it has a special, can not be shown here.
Idea Right button cannot create new Java Class