IntelliJ IDEA, JDK, and Tomcat are installed by yourself. The installation procedure is omitted.

1. Create and configure the project

1.1 Creating a Project

Select the file-new-project menu, in the New Project screen, follow the steps below and click Next

1.2 Set the Project name

1.3 Starting the Configuration Project

After selecting the Project directory, right-click and Open the “Open Module Settings” menu or F4 to Open the Project Structure dialog box

A project can have multiple subprojects, each of which is equivalent to a module. In general, our project is a single project. IntelliJ IDEA is also a single project by default, so only one module needs to be configured.

1.3.1 configuration Source

Create two new folders under project-web-WEB INF: classes and lib

  • Sources: Displays the directory resources of the project. Which directories are required during project deployment. Different colors represent different types.

  • Paths: You can specify the compile output directory of the Project, that is, the compile output address of the Project class and test class (instead of the default output address of Project)

  • Dependencies: Dependencies of the project

1.3.2 configuration Paths

Change the two output paths to the full addresses of the classes you just created

1.3.3 configuration Denpendencies

There’s a small plus (+) on the right, click on the + and then select JARs or directories…

Select the lib address you just created

Select the Jar Directory

At this point, the project is configured

Among them, Project:

  • Project Name: Defines the name of the Project

  • Project SDK: Sets the JDK to be used by the Project. You can also add another VERSION of the JDK here

  • Project Language Level: This is similar to JDK, except that if you set JDK1.8 and only use 1.6 features, you can set the language level to 1.6. This is the minimum required JDK feature for Project compilation checks

  • Project Compiler Output: The default compilation output directory in a Project

Libraries can display the jars that are added, add jars, and put multiple jars into a group, similar to jar sorting

Facets 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 select panel, the right will display some Settings for that frame

2. Configure Tomcat

Select the menu bar [Run] – [Edit Configurations] or Add Configurations in the upper right corner to open the debug configuration dialog box

2.1 Creating a Tomcat Server

Click the + sign in the upper left corner and select Tomcat server-Local Server (in this case, the Local Server is used) to open the following configuration dialog box

IntelliJ Community (i.e., the free version) does not have Tomcat Server as an option, but the paid version does

2.2 Setting the Server Name

Configure server and JRE information. Jar packages can be added to the server libraries as required

In the second Deployment TAB, there is a green + on the right, click the + sign, add an Artifact and set the Application Context (note that the latest version of this setting is at the bottom)

There are some changes to the panel once it’s ready to be installed to prove that Tomcat is ready

Artifacts Package deployment Settings for the Artifacts project. This is a key part of the project configuration.

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.

An artifact is a solution for loading project assets for testing, deployment, or distributed software. Examples include compiling classes centrally, archiving Java application packages, using Web programs as directory structures, or archiving Web programs.

An artifact can serve as an archive file, or as a directory structure containing the following structural elements.

  • One or more compilation modules

  • The class library that the module depends on

  • Resources collection

  • Other artifacts

  • Separate file directory or archive

That is, the integration of compiled Java classes, Web resources, etc., for testing, deployment, etc. In other words, you need to use the exploded format to package a module, such as war Exploded, war, JAR, EAR, and so on. Artifacts are available for a module to deploy to the application server.

  • Jar: Java ARchive, typically used to aggregate a large number of Java class files, associated metadata, and resource (text, images, etc.) files into one file for distribution of Java platform applications 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), and other resources that make up a Web application

  • ‘Exploded’ : Here you can understand the meaning of spreading out, uncompressed. This is the directory structure of war, JAR, and so on before compression. It is recommended to use this mode during development so that the effects of modified files are immediately apparent.

By default, the Modules and Artifacts output directory of IDEA is already set. There is no need to change it. Classes are automatically generated in the WEB-INF directory when you type the war package and put the compiled files in it.

2.3 hot deployment

If you want to modify the content of the Web project, Tomcat automatically reloads files to avoid manually restarting the service. You need to perform the following simple configuration: Select Update Classed and Resources in update

Be sure to select the WAR package whose name contains the exploded suffix, otherwise the redeployment of the modified file will not take effect.

3. Run

Write braille in index.jsp for testing purposes

To execute the Web program, click the green Run button in the upper left corner

Normally, the browser will automatically open a specific URL address, of course, you can also enter the project from the browser to see the launch addresshttp://192.168.123.100:8080/java_web/

When you click Run Tomcat, the default is to do the following:

  • Compile, IDEA does not compile after save/autosave, unlike Eclipse’s save is compile, so it is compiled once before running the server. The compiled class file is stored in the specified project compilation output directory

  • Create the directory structure based on the Settings in the artifact

  • Copy all files from the root directory of the Web resource to the artifact directory

  • Copy the classes directory from the compile output directory to web-INF for artifact

  • Copy the required JAR package from the lib directory to WEB_INF under artifact

  • Run the server. If necessary, the server automatically opens the browser to access the specified URL