简体   繁体   中英

Default Maven Project Structure in IntelliJ is inconsistent

When I create a new Maven project in IntelliJ, I normally expect this:

在此处输入图片说明

However, I occasionally get this:

在此处输入图片说明

Why does my project sometimes look like Picture 1 and other times look like Picture 2? Those two projects are built in the same way: Maven without archetypes. What am I doing wrong that I do not get Picture 1's structure?

To start with, src/main/java does not seem to be marked as sources root in neither of the pictures. Notice the small red dot on your App.java file? That should be a "Class symbol" if your project is correctly set up.

To fix this, right click the src/main/java folder and choose Mark directory as -> Sources Root . Your project structure should now look like this:

标记为源根

When it comes to the difference between your two screenshots, it is nothing but a difference in the presentation. There is something called Title Bar Context Menu (the small cogwheel above the folder structure) which lets you customize its behaviour.

The second of your screenshot seems to have the Flatten Packages option set, which forces empty packages to be "flattened":

扁平包装

Once again, this is just plain presentation. There is not a com.example folder on the disk, but two folders com/example .

Without the Flatten Packages option, the structure would look like my first screenshot.

So again, it is really just a presentation issue. Exactly why you experience different behaviours when creating new projects is hard to say without more context, but simply use the Title Bar Context Menu to customize the look to be as you want. These settings are saved in your .idea folder per project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM