idea to create a new 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

(注意New Project里面不是选择的web 而是java)

intellij中web项目 默认网页根目录是web 

项目配置可参考2中的几个地方 根据自己的需求自己修改

artifact中out directory 可以指定到任何地方 项目打包编译到指定的目录下  

在intellij中启动tomcat  都会以对应war包out directory的设置的目录为工作空间

tomcat配置请参考http://my.oschina.net/u/140593/blog/177042#OSC_h1_2 中的2-7

4.Maven项目的部署

在intellij中 maven项目还是可以按照maven的打包编译 参考图中的几个生命周期 手动去执行

因为maven项目的约定 是项目打包编译到 target目录下  

所以我们在2中配置都应该去遵循maven的配置约定进行修改

这样我们的项目在文件修改或者热部署的时候  intellij的编译才能和maven项目保持一致 

(如果是在intellij中创建maven项目 那个intellij会给你配置好所有的配置  

基本不用修改 我们可以创建一个springmvc的例子进行参考)

需要注意的地方是:

maven项目  artifact中out directory 的目录名 

一定要和pom文件中build的finalName一致

另外pom文件中 要配置<packaging>war</packaging>

比如pom中配置的项目bulid finalName叫做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://10.200.1.11:23101/article/api/json?id=326564673&siteId=291194637