本篇文章将为大家详细介绍如何解决使用idea addconfiguration时没有tomcat选项的情况。
一、检查安装路径
首先,我们需要检查tomcat是否已经在我们的电脑上正确安装。可以前往tomcat安装目录查看是否有bin、conf等文件夹存在。
//Windows系统下的tomcat安装目录一般在 C:Program FilesApache Software FoundationTomcat X.X //MacOS系统下的tomcat安装目录一般在 /Library/Tomcat/Home
如果安装路径不对,我们需要重新安装tomcat,可以从下载地址(http://tomcat.apache.org)获取最新版本的tomcat。
二、添加tomcat
在idea中添加tomcat有两种方式:
1、直接添加tomcat
在File->Settings->Build, Execution, Deployment->Application Servers中找到Add按钮,手动添加tomcat,如下图所示:
//在设置页面依次点击 File -> Settings -> Build, Execution, Deployment -> Application Servers -> Add
2、使用“+”添加tomcat
在Run->Edit Configuration->Add New Configuration中找到“+”,选择Tomcat Server(Local)即可。如下图所示:
//在配置页面依次点击 Run -> Edit Configuration -> Add New Configuration -> “+” -> Tomcat Server(Local)
三、配置tomcat
配置tomcat首先需要在Configure中对Tomcat设置其所在路径,并配置项目的输出路径。具体步骤如下:
1、在Run->Edit Configuration->Tomcat Server中选择刚才添加的tomcat实例:
2、在Configure中对Tomcat进行配置:
3、在Deployment中配置项目的输出路径(output directory),如下图所示:
四、测试运行
最后,在idea的Run/Debug Configuration中选择已配置好的tomcat,点击Run/Debug,开始测试运行tomcat。
//在Run/Debug Configuration中选择刚才配置好的tomcat Run -> Debug Configuration -> 选择刚才配置好的tomcat -> Run/Debug
五、完整代码示例
//配置tomcat //需要在Configure中选择Tomcat所在路径,并配置项目的输出路径