Take you in-depth understanding of IDEA's Project Structure

Intellij IDEA use tutorial related series catalog

One of the conveniences of the IDE development tool is that many configuration items can almost directly use the default items. However, it is inevitable that different projects need targeted configuration. This article will take you to sort out the various functions in the Project Structure in detail, and pay attention to the collection in case of emergency.

Let me talk about the reason for writing this article. I opened a group of SpringBoot projects in Idea in the project, and the results of the compilation and log output were inconsistent with expectations. So I carefully studied the configuration items of Project Structure and found that there are many useful items here. The functions are summarized and shared with everyone.

Project Structure is the "project structure", which covers almost all the personalized configuration items of a project, including the functions of Modules, Facets, Libraries, Artifacts and SDK.
Insert picture description here

Ways to open the project structure

There are two ways to open the project structure configuration. One way is to click the icon at the position ① above to directly open the related configuration interface.

Another way is to open it via shortcut keys. The default shortcut key for Windows operating system is "Ctrl+Shift+Alt+S"; the default shortcut key for Mac operating system is the combination of "command + ;".

In the first way, if you can't find the corresponding configuration, teach you a big trick when using Idea: "Help" search.
Insert picture description here

Click on the Help menu and enter the Project keyword to search. By default, all options related to the Project keyword will be matched. When the mouse is moved to the corresponding result, the menu position of the corresponding content will be automatically displayed on the left side. Of course, you can also directly Click to open.

Not only can this be done here, but most of the operations can be done like this, is it very cool to use!

Project configuration items

Under normal circumstances, the first display content selected by default after opening is Project. Focus on items 1, 2, 3, and 4 in the figure.
Insert picture description here

The first item, Project name, project name. Personally, the project name here is generally consistent with the project directory name and the name in the pom file. Avoid inconsistencies, and at the same time, avoid IDEA from displaying multiple name logos on the left.

If you are opening a group of projects, such as all springboot projects, I will change the name to something like springboot-all instead of the name of one of the projects (the first one by default).

The second item, Project SDK. Configure the SDK usage of the project. This is usually used more often. For example, when you open a new project, you need to check whether the SDK version is consistent with your expectations. You can also edit the SDK in the Edit on the right.

Clicking edit here will jump to SDKs in Platform Settings for operation. Take a look at the figure here, the operation is relatively simple, so I won't expand it.
Insert picture description here

The third item, Project language level. Select the Java language level to be supported. If it is multiple Modules (can be understood as a group of projects), it will take effect for all Modules.

The choice of different JDK versions has a certain impact on the syntax of the code. For example, if you choose a version before JDK8, then there will be an error in the code if there is a Lambda-based syntax. At present, JDK8 is the most used one. Of course, if your project is relatively old or relatively new, you can also choose other versions.

The fourth item, Project compiler output. Specify the path where IntelliJ IDEA will store the compiled results.

This is the problem I said at the beginning. For a single project, you can configure an output path, and you can also configure it independently in the Module mentioned later.

But for multiple Module projects, it will appear that everyone shares an output directory. At this time, if the output log file path is in the form of "./log", the log may not be printed to its sub-items, but output under the path specified here.

Modules configuration items

The configuration in Modules is more commonly used when a group of projects, you can configure the parameters of each project independently. Including project name, directory structure, output path, dependencies, etc.
Insert picture description here

Let's analyze the four items marked in the figure below, of which the third and fourth items belong to the sub-items of the Source option.

The first item, the plus sign can import and add various Module items, of course, the minus sign at the back can remove the corresponding items.

The second item, the name of the project, and the method of use are the same as the previous one, and it is also recommended to keep the same in many places.

The third item, the JDK version, is the same as in the Project, but here is for the current Module.

The fourth item is the project directory structure. The module development directory is classified into folders, and different types of files are assigned file types. The above is divided into Sources, Test, Resources, Test Resources, Excluded.

As the name suggests, Sources is the Java source code, Test is the source code of the test, Resources is the resource file, Test Resources is the resource file used by the test, and Excluded is the excluded item (such as the compiled trrget directory).

The more frequently used scene here is the newly added folder. Right-click a top-level directory, and "New Folder" will pop up to create a directory, and then you can specify the type of the new folder. Common situations such as creating a project without test or Test Resources, you can add a directory here, and then specify the directory type.

There are Paths and Dependencies on par with the Sources option. These two operations are relatively simple, Paths is used to specify the compiled output path.
Insert picture description here

Generally, the default value is sufficient. Among them, Inherit projecty compile output path inherits the project compile output path and uses the path specified for the project. That is, the out file path set in the Project option.

Use module compile output path, use module compile output path; Output path, compile output path; Test output path, test code compile output path.

The following JavaDoc uses a list of available control combinations to store the external JavaDocs associated with the module. If it is not used frequently, it will not be demonstrated in detail.

The other is Dependencies, which mainly configures the jar package to depend on related content.
Insert picture description here

The JDK can also be configured here, and other dependencies can be introduced through the plus sign below, and the Scope corresponding to the corresponding jar package can also be configured.

The above explained many JDK configuration options. If there is a problem of JDK version modification or inconsistency during actual combat, it is recommended to check whether there is any problem with the JDK version from beginning to end.

Libraries option configuration

In the Libraries tab, you can define the module SDK and form a list of module dependencies.

Insert picture description here

Through the operations in the plus sign, a new project library can be created, categories can be set, and operations can be deleted.

Facets option configuration

The Facets option is mainly used to express the characteristics of the module, such as Web, Spring, Hibernate, etc.

Insert picture description here

Artifacts option configuration

Artifact is a concept in maven. Here indicates what form the module is packaged into, such as war exploded, war, jar, etc.;
Insert picture description here

This form is rarely used when based on the SpringBoot project, and it is used more frequently when the web-based war package is used.

Among them, the web project has an exploded type, which can be understood as meaning not to archive, which means that folders, jsp pages, and classes are directly deployed into the container. It is recommended to use this mode during development to facilitate hot deployment.

By default, the output directories of IDEA's Modules and Artifacts have been set and do not need to be changed. The classes directory will be automatically generated in the WEB-INF directory when the war package is opened, and the compiled files will be put into it.

other options

I won’t say much about the other options, which are not commonly used. Among them, the SDKs option is the system development tool, the global SDK configuration, and the new JDK version can be configured here. Global libraries are global class libraries, and some commonly used class libraries can be configured. Problems can be repaired according to the prompts when the project is abnormal (FIXED).

Guess you like

Origin blog.csdn.net/shi_hong_fei_hei/article/details/112635612