Java project folder structure in IntelliJ IDEA

后端 未结 4 427
别跟我提以往
别跟我提以往 2021-02-04 03:17

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

Multiple sources (like this) suggest the following structure:

.
│ .idea    
└─         


        
相关标签:
4条回答
  • 2021-02-04 03:36

    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.

    0 讨论(0)
  • 2021-02-04 03:36

    Simply close intellij and delete any existing .IML file from the project root will do it

    0 讨论(0)
  • 2021-02-04 03:45

    In Project Structure Settings,select Modules -> choose any of the mark as to set the folder type to be of specific type. Then do mvn clean and mvn compile

    0 讨论(0)
  • 2021-02-04 03:46

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

    <sourceDirectory>src/main/java</sourceDirectory>
    
    0 讨论(0)
提交回复
热议问题