Deployment configuration of IntelliJ IDEA WEB project

1 Introduction

    Although Intellij IDEA has been used for more than four months, most of the functions in it are relatively familiar, but many details are still unclear. In the past few days, another team in the company has also replaced Intellij IDEA to help them migrate projects. Because it is a non-maven project, I have encountered a lot of problems, and I have studied it again, and I will sort it out below

2. Project Configuration ( Project Structure )

2.1 Project 

project compliler output: configures the default compilation output general directory in the project

It is also explained in English, each module can set its own special output directory, so this is basically useless

2.2 Modules

The module of the project, a project can have multiple sub-projects, each sub-project is equivalent to a module

Generally, our project is only a single one, so we only need to configure one module, and we can add a framework to the module

According to the things used in our project, add the corresponding framework, and determine the relevant configuration file in the framework (because the file structure of the project may be different under different IDEs, we should pay attention to the configuration of the imported project)

The module configuration root is divided into three tabs: Sources - Paths - Depedencies

Under the Sources tab, the directory resources of the project are mainly displayed.   Those directories that are required for project deployment have color prompts.

(For example, green is the test directory, orange is the target directory, and these deployments are not needed. The big red is the blue that is not under my project, and the blue is really needed to deploy) 

under the Paths tab 


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)

Depedencies are dependencies of the project

We can click the + sign on the right to add lib. For example, the lib of tomcat is added by default and is Provided 

(similar to the jar dependencies in maven)

Provided means that it is ignored when the project is deployed and only used when the project is recompiled

Compile is a Test deployed with the project and it is not deployed

2.3 Libraries

It can add project jar packages and put multiple jars in a group, similar to jar package sorting

The jars added under this will be displayed in Depedencies (not vice versa)

2.4 Facts

The facade of the project, to be honest, I really don't know what this is for. It's similar to modules, mainly to confirm it.

2.5 Artifacts

The packaging and deployment settings of the project, this is the key place in the project configuration

Pay attention to the red box

The first is that we need to add the deployment package of the project. Note that the choice is the exploded war package.

The second is the output directory of the project is not a maven project, this can be set to anywhere 

(The maven project needs special attention to this later)

The third is the output structure (output layout) several files in the reference diagram 

(If the maven project does not use maven's packaging and compilation, note that the lib under WEB-INF in the figure must have the jar deployed by the project)

3. Creation and deployment of non-Maven projects

Create File - New Project - Java - Web Application

(Note that New Project is not the selected web but java)

The default web page root directory of the web project in intellij is web 

The project configuration can refer to several places in 2 and modify it according to your own needs

The out directory in the artifact can be specified anywhere. The project is packaged and compiled into the specified directory.  

Starting tomcat in intellij   will use the directory set corresponding to the out directory of the war package as the workspace

For tomcat configuration, please refer  to 2-7 in http://my.oschina.net/u/140593/blog/177042#OSC_h1_2

4. Maven project deployment

In intellij, the maven project can still be manually executed according to several life cycles in the maven package and compilation reference diagram

Because the convention of the maven project is that the project is packaged and compiled into the target directory  

So we should follow the maven configuration convention to modify the configuration in 2

In this way, the compilation of intellij can be consistent with the maven project when the file is modified or hot deployed. 

(If you create a maven project in intellij, intellij will configure all the configurations for you  

Basically without modification, we can create an example of springmvc for reference)

Things to pay attention to are:

The directory name of the out directory in the  maven project   artifact

It must be consistent with the finalName of the build in the pom file

In addition, the pom file needs to be configured<packaging>war</packaging>

For example, the project  bulid finalName configured in pom is called ROOT

Then our out directory is E:\project accumulation\test1\ target\ROOT 

After compiling and packaging the project through maven

In the configuration of the server, you can remove the two options in the red area in the figure below to avoid recompiling and packaging each time you start 



5. Summary

    This article basically summarizes the problems of web project deployment in intellij and how to configure them. Because there are no specific instructions on the Internet, these are all my own explorations. If there is anything wrong, you are welcome to correct me.

Guess you like

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