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的安裝目錄。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM