IDEA部署 java Web项目 常见配置

前言

从eclipse上转到idea上,第一次使用idea部署web项目,真折磨人,写了一个 helloworld 5分钟,了解idea部署web项目5小时。

我使用的是idea 2019.1版本,其他版本大致相同,下面一步步进行web项目部署,并且对其中遇到的idea一些常见设置进行解释。

一:添加Tomcat服务器

在项目编写完成后,首先要添加一个tomcat服务器

 

 

 

 二:部署项目

 

 

 war与war exploded的区别

 

选择war exploded部署好项目后,仍然来到这个页面

 

 

介绍一下 Deploy application configured in Tomcat instance

 

Deploy application configured in Tomcat instance 有什么用?

 

下面是我在Stack Overflow 看到的:

 

This setting controls whether the apps you already have present in TOMCAT_HOME\webapps directory will be deployed when Tomcat is started from IntelliJ IDEA.

By default that would deploy the following:

  • docs
  • examples
  • host-manager
  • manager
  • ROOT

If you don't need any of these default apps or any of your other apps put there manually to be deployed, disable the Deploy applications configured in Tomcat instance option. This will make the server startup faster and it will use less memory.

Documentation page you are looking for is available here, here is the official explanation for this option:

The Tomcat configuration files, among other things, may list the applications that should be deployed at the server start. If this check box is selected, all the applications so listed will be deployed on the server in addition to the artifacts specified on the Deployment tab. If the check box is not selected, only the artifacts and the external resources specified on the Deployment tab will be deployed.

 

也就是说,

当你把这个框给勾上时,此时在你启动tomcat服务器后,不仅会部署你当前的项目,而且还会部署在 ${tomcat安装目录}/webapps/ 下的其他项目,例如tomcat出厂就自带的docs examples等项目,tomcat部署完成后,你只访问 localhost:8080 就能成功进入tomcat首页,是因为,你在部署你当前项目的同时,还部署了webapps目录下的root 项目。

如果没有勾上这个框,那么你访问localhost:8080会抛出404,你只能访问你当前项目的全路径,拿我的来说就是:localhost:8080/springmvc01_helloworld/  才不会抛出404错误。

 

三:查看tomcat启动后,控制台打印信息,CATALINA_BASE与CATALINA_HOME

这里,主要关注CATALINA_BASE和CATALINA_HOME两个目录,这两目录有什么区别?

简单来说,

CATALINA_BASE是idea为当前项目建立的工作目录,我们部署的项目就放在这里(上面的设置介绍中,我有提到),使用war exploded部署项目时,并没有把项目打包到tomcat的webapps目录下,我们的项目部署的位置就在这儿!!! 查看这个目录有什么?

看看conf目录里面有什么?竟然还有tomcat的配置文件server.xml

对比一下tomcat的安装目录:

看到这里就明白了一件事,idea为每个部署的项目新创建了一个tomcat实例,这就是一个工作目录,这个实例与我们的tomcat相比,没有bin和lib库等信息,只有一些配置信息,仍然与原来tomcat共用bin和lib目录。

CATALINA_HOME则是tomcat的安装目录。

 

posted @ 2019-08-06 17:56  BoildWater  阅读(7115)  评论(1编辑  收藏  举报