Java project folder structure in IntelliJ IDEA

What is the acceptable folder structure for Java projects in IntelliJ IDEA?

Several sources ( like this ) suggest the following structure:

[] .idea [] src [] main [] java com.simpleproject SimpleClass.java [] resources [] test [] java com.simpleproject SimpleClassTest.java [] resources 

I know this worked before, but right now complains java.lang.SecurityException: Prohibited package name: java

Apparently, java not resolved as a package name. I do not understand why this is sometimes acceptable, and sometimes unacceptable. Can someone provide a complete example of an acceptable project folder structure in a Java project in IntelliJ IDEA?

+11
java intellij-idea
source share
4 answers

This is the main folder structure of the Maven project. IntelliJ usually recognizes this and sets sensual defaults for you.

If this is not the case (or if it was, but you changed them later), you need to configure the Java folder as the sources folder (that is, in the folder that contains the source code).

For this you need:

  1. Go to your project structure settings: File > Project Structure
  2. Select your project in the middle panel
  3. Select the Sources tab in the right pane.
    • Note to comment (thanks @Line): In IntelliJ 2018.3.5, you "select the" Modules "tab in the left panel."
  4. Go to src/main/java folder and select it
  5. Mark as Sources

Repeat these steps for the folder with tests (mark as "Tests"), resources (mark as "Resources"), test resources (mark as "Test resources"), etc.

+24
source share

Your configuration on the IntelliJ File > Project Structure page will be overridden by the pom.xml project after each clean install . To prevent this, you need to configure the source directory in pom.xml , as shown below:

 <sourceDirectory>src/main/java</sourceDirectory> 
+3
source share

Just close intellij and remove any existing .IML file from the project root directory.

0
source share

In the project structure settings, select "Modules" → select any label to set the type of folder of a certain type. Then do mvn clean and mvn compail

enter image description here

enter image description here

0
source share

All Articles