Java project folder structure in IntelliJ IDEA

Atte Juvonen :

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

Multiple 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 has worked before, but right now it is complaining java.lang.SecurityException: Prohibited package name: java

Apparently, java is not allowed as a package name. I don't understand why it's sometimes acceptable and sometimes not acceptable. Can someone provide a complete example of an acceptable project folder structure in a Java project in IntelliJ IDEA?

blurfus :

That is the basic folder structure of a maven project. IntelliJ usually recognizes this and sets up sensical defaults for you.

If it didn't (or if it did but you modified them afterwards), you need to set up your java folder as the sources folder (i.e. the folder that contains the source code).

For this, you need to:

  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 panel
    • Note from a comment (thanks @Line): In IntelliJ 2018.3.5, you "select 'modules' tab in left panel".
  4. Navigate to the src/main/java folder and select it
  5. Mark it as Sources

Repeat for test folder (mark as 'Tests'), resources (mark as 'Resources'), test-resources (mark as 'Test Resources'), etc.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=449152&siteId=1