环境
- 阿里云ECS
- windows server 2016
- idea 2018.1
- tomcat 9.0 windows安装版
idea设置
idea 设置部分网上教程比较多,这里略过,大家可以参考下面的帖子
https://segmentfault.com/a/1190000012762629
请参考该帖子的 1、6 两章设置 idea remote tomcat
服务器设置
这里我们着重讲一下服务器设置
sftp服务开启
https://blog.youkuaiyun.com/shutingwang/article/details/52981751
可以将ftp目录设置到 tomcat/webapps 目录,这样 idea remote tomcat 设置中所有路径填 / 即可
但是注意 idea remote tomcat 设置项 Mapped as 要设为 ./ 不然 idea 会提示错误
Error during artifact deployment. See server log for details.
tomcat设置
在 tomcat 配置中添加 Java Options 配置如下
-Dcom.sun.management.jmxremote=
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=<服务器IP>
-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:61450,suspend=n,server=y
要注意下面这项设置
-Dcom.sun.management.jmxremote.rmi.port=1099
网上的大多数 remote tomcat 教程中缺少此项配置,会导致 tomcat 启动错误
Error running ‘x.x.x.x’
Unable to connect to the x.x.x.x:1099, reason:
java.rmi.ConnectException: Connection refused to host: x.x.x.x; nested exception is:
java.net.ConnectException: Connection timed out: connect
debug tomcat 设置
远程 debug tomcat,需要将 idea remote tomcat 配置中提供的参数加入服务器 tomcat 配置
图片中的参数复制粘贴到上面的服务器 tomcat Java Options 配置中
这里要注意 adress 参数要配置为 0.0.0.0:port
-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:61450,suspend=n,server=y
如果只配置端口,debug 启动 tomcat 时会出错
Error running ‘39.106.114.247’: Unable to open debugger port (39.106.114.247:61450): java.net.ConnectException “Connection refused: connect”
备注
以上配置涉及到的 1099、8080、debug 端口,需要在阿里云安全组中配置访问规则