IDEA project configuration and web deployment

It is very well written, and I will share it with you here. The original link: https://www.cnblogs.com/deng-cc/p/6416332.html


1. Understanding of project configuration

The most important various setting items in IDEA is this Project Structre, which is related to the operation of your project, even if you lack arms or legs. Recently, the company happened to use IDEA, which was familiar to me before, instead of Eclipse. In order to understand and use it more deeply, I found various materials and studied it again. Here is the output.

1.1 Project

  1. Project name : defines the name of the project;
  2. Project SDK : Set the JDK used by the project, or you can add other versions of JDK here;
  3. Project language level : This is similar to JDK, the difference is that if you set JDK1.8, but only use the features of 1.6, then you can set the language level to 1.6, which is the minimum required JDK feature when compiling and checking the project ;
  4. Project compiler output : The default compilation output directory in the project, as shown in the yellow part of the figure, in fact, each module can set its own special output directory (Modules - (project) - Paths - Use module compile output path), so this setting is a bit Chicken ribs.

1.2 Modules

1.2.1 Add or delete sub-projects

A project can have multiple sub-projects, and each sub-project is equivalent to a module. Generally, our project is only a single one, and IntelliJ IDEA is also in the form of a single subproject by default, so only one module needs to be configured.
(The two projects here are imported for example reference only)

1.2.2 Subproject configuration

Each subproject corresponds to the three configuration options of Sources, Paths, and Dependencies:
  • Sources : Display the directory resources of the project, those are the directories needed when the project is deployed, and different colors represent different types;
  • Paths : You can specify the compilation output directory of the project, that is, the compilation output address of the project class and the test class (replaces the default output address of the Project)
  • Dependencies : the dependencies of the project


 

1.2.3 Adding and removing frameworks (Web Deployment-1)

The framework it uses can be defined under each sub-project, and the settings for the Web part are highlighted here.

1.3 Libraries

The added jar packages can be displayed here, and jar packages can also be added, and multiple jars can be placed in a group, similar to jar package sorting.

Here each jar package is made a separate group by default (not tested, to be determined).

1.4 Facets

The official explanation is:
When you select a framework (a facet) in the element selector pane, the settings for the framework are shown in the right-hand part of the dialog.
(When you click on a technical frame in the left selection panel, some settings of this frame will be displayed on the right)

To be honest, I didn't feel it had any effect.

1.5 Artifacts (Web Deployment-2)

The packaging and deployment settings of the project, this is the key place in the project configuration, let's focus on it.

First understand its meaning and take a look at the officially defined artifacts:
An artifact is an assembly of your project assets that you put together to test,  deploy or distribute your software solution or its part.  Examples are a collection of compiled Java classes or a Java application packaged in a Java archive, a Web application as a directory structure or a Web application archive, etc.

That is, the integration of compiled Java classes, Web resources, etc., for testing, deployment and other work. To put it more vernacularly, it means how to package a module, such as war exploded, war, jar, ear and so on. A module with Artifacts can be deployed to the application server.
jar : Java ARchive, usually used to aggregate a large number of Java class files, related metadata and resource (text, pictures, etc.) files into a single file in order to distribute Java platform application software or libraries;
war : Web application ARchive, a JAR file that contains JSPs, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) for distribution, and other resources that make up a web application;
exploded : Here you can understand it as expanding, not compressing. That is, the directory structure of war, jar and other outputs before they are compressed. It is recommended to use this mode during development, so that the effect of modifying the file can be displayed immediately.
By default, the output directories of IDEA's Modules and Artifacts have been set and do not need to be changed. When they are packaged into war packages, classes will be automatically generated in the WEB-INF directory, and then the compiled files will be put in.


You may not understand the output directory here. Didn't you configure the output directory for file compilation before? Why is there still a directory that integrates these resources? What does it do? 

Actually, when you click to run tomcat, it starts doing the following by default :
  • Compile, IDEA will not compile after save/auto-save, unlike Eclipse's save that compiles, so it will compile once before running the server. After compilation, the class file is stored in the specified project compilation output directory (see 1.2.2);
  • Create the directory structure according to the settings in the artifact;
  • Copy all files in the root directory of the web resource to the artifact directory (see 1.2.3);
  • Copy the classes directory under the compilation output directory to the WEB-INF under the artifact (see 1.2.2);
  • Copy the required jar package in the lib directory to WEB_INF under artifact;
  • Run the server, after successful operation, if necessary, it will automatically open the browser to access the specified url.

It should also be noted here that the configured artifact needs to be added in tomcat:

2. Reference link


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325899062&siteId=291194637