IntelliJ IDEA configure Tomcat to run web tutorial project (multi-map)

https://www.cnblogs.com/BaleW/p/8694217.html

White one, draws a lot of people blog, and then summarizes some of their own map, as far as possible in detail. In the configuration process, there are a lot of questions. If the reader can give me after seeing the answer, please leave a message. Idea Please install their own good, also you need to install Maven and Tomcat, each configured environment variable.

I configured a multi-module web project with Maven and Tomcat. I think my configuration process a little strange, no way, not just check around, there may be a more convenient way. But I also can successfully start the Tomcat jsp visit.

First create a Project. I click on the Next, because the first Project just as a parent module to use.

And also Next.

After entering the project name, Finish.

 

 After Finish, obtain the following new project. Then I will continue to build a Module, so you can delete the source folder src, anyway, will not use it.

 Project name, right-click, New a Module.

I set this Modlue Maven project, select Create from archetype, and then select the maven-archetype-webapp. Select this new prototype comes with a Maven project will webapp folder, which comes with a WEB-INF and a index.jsp, if you do not check, you can manually create your own two or more. Next Once you have selected.

 

Enter GroupId and ArtifactId, Version default. The company's domain name is generally GroupId upside down. After you follow this rule can be written. I am here just to write.

ArtifactId generally your module name. That is, you write ArtifactId is valid, while the Module built on Jiaosha.

This step is to set your Maven path. Not much to say. Next.

Set the name of the Module. As stated above, and ArtifactId try to set the same name. If case you readers can try a different name, ha ha, I do not try. Finish.

 点击Finish后,模块就创建完成了。Idea在创建一个Maven项目后,会先下载一些插件,这一过程很短,十几秒就完成。完成后,模块的结构如图。

这里插一嘴,如果第一次使用idea的朋友,可以去文件夹里面看一下你的项目。servletDemo文件夹有一个.idea 和out文件夹。这表明servletDemo是一个项目。

而servletDay01文件夹如下图。它是依赖于父模块的。

好了,回到正题。后面还要好多步骤呢。如图操作,我们添加Tomcat。

 点击Edit Configurations后,如图

 

点击加号

 

 这里就是配置Tomcat的一些信息。如果你的Application server里面没有本地的Tomcat,你需要Configure找到本地Tomcat的路径。Tomcat需要相关版本的JRE支持。

After launch右边的浏览器你可以选择自己习惯的。我使用的Google的Chrome,你用IE什么的也行。下面的HTTP port是你Tomcat运行时使用的端口号。如果冲突,可改一下。

点击OK。

OK后,我们就配置好了Tomcat,此时我们会看到。项目中显示了我们刚才配置的名叫Tomcat 5.5的Tomcat。Tomcat我们就先配置到这里。我们再去我们的servletDay01这个Module里配置一些东西。

下面我们需要打开Project Structure。

打开后,在Modules中我们可以看到,我们有两个Module。在servletDay01中,右键,Add一个Web。

这里我就有疑惑了,这个Web是啥?然后如图所示,我们做相应设置。点击OK。

然后我们配置Artifacts。在Artifacts中,点击绿色加号。选择Web Application:Exploded。这里我就比较迷茫了。我不知道什么是Web Application Exploded。但是一会儿我们可以在Tomcat中设置Deploy,然后选择这个Artifacts。

这里没有需要更改的,可以直接点击OK。

Module配置好了。我们回去设置Tomcat的Deployment。Deployment中设置的项目,可以在Tomcat运行时进行加载。这里,我们选择Artifact。这里需要注意,只有像我刚才那样设置了Artifact才会出现这个Artifact。否则只有External Source。

点击Artifact后, 自动加载了servletDay01:war exploded。这里我们需要设置一个Application context,斜杠开头,后面跟着你的模块名称(idea中我习惯叫模块。如果是eclipse的用户,这个就是项目名称)。点击OK。

 

至此,全部配置完毕,我们可以运行Tomcat了。

运行成功

 

此时如果修改index.jsp后,直接刷新页面,页面不会有变化。我们可以设置Tomcat的更新动作(这个设置是所谓的热部署么?不知道)

设置了之后,再修改jsp文件后,不用重启Tomcat也可以看到页面的改变了。

写到这里,还是有疑惑的。为什么在浏览器输入的地址,不加index.jsp也能打开这个jsp文件呢?是idea的某些设置么?希望知道的人可以留言。

 

Guess you like

Origin blog.csdn.net/qq_28817739/article/details/93843731