[英]How to debug a Tomcat 7.x/8.x webapp locally with IntelliJ Community (free) version in Linux?
我知道这可能与 Ultimate Edition 有关,但是有没有办法在 Community Edition 中本地调试这些应用程序?
If you have worked with IntelliJ Ultimate edition you have seen that it is possible to add a Tomcat configuration where you can both debug or run your Tomcat container from within IntelliJ.如果您使用过 IntelliJ Ultimate 版,您就会看到可以添加 Tomcat 配置,您可以在其中从 IntelliJ 中调试或运行您的 Tomcat 容器。 It is possible to get your IntelliJ Community version to do the same thing for you with a little bit of extra settings.通过一些额外的设置,可以让您的 IntelliJ 社区版本为您做同样的事情。
This is a remote monitoring and management tool for Tomcat.这是Tomcat的远程监控管理工具。 JMX related settings is not needed to enable your debugging.启用调试不需要 JMX 相关设置。 Although it can be useful for monitoring purposes through JConsole ( read more ).虽然它对于通过 JConsole 进行监控很有用( 阅读更多)。
You instance of Tomcat must be already up and running for the Community version to be able to attach itself to the Tomcat process.您的 Tomcat 实例必须已经启动并运行,社区版本才能将其自身附加到 Tomcat 进程。 While your tomcat will be running on a port (Tomcat default is 8080), you also need to setup another port for the debugger to attach itself to your running version of Tomcat (9999 in our example).虽然您的 tomcat 将在一个端口上运行(Tomcat 默认为 8080),但您还需要为调试器设置另一个端口以将其自身附加到您正在运行的 Tomcat 版本(在我们的示例中为 9999)。
Settings include changes you need to make to your Tomcat and configurations you need to do on your IntelliJ community edition.设置包括您需要对 Tomcat 进行的更改以及您需要在 IntelliJ 社区版本上进行的配置。
Please follow the order in changes.请按照更改顺序。
Stop your Tomcat if it is running in your Tomcat bin folder through: ./shutdown
or ./catalina stop
如果 Tomcat 在 Tomcat bin 文件夹中运行,请通过以下./catalina stop
Tomcat: ./shutdown
或./catalina stop
Add the following line to your catalina.sh file under the commented JAVA_OPTS set statement:将以下行添加到 catalina.sh 文件中注释的 JAVA_OPTS set 语句下:
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999" JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999"
HINT: I have used
JAVA_OPTS
notCATALINA_OPTS
as the comments in catalina.sh suggests it is preferred to useJAVA_OPTS
.提示:我使用的是JAVA_OPTS
而不是CATALINA_OPTS
因为 catalina.sh 中的注释表明最好使用JAVA_OPTS
。 However, it is possible to useCATALINA_OPTS
in a similar manner to enable the debugging.但是,可以以类似的方式使用CATALINA_OPTS
来启用调试。
./catalina.sh start ./catalina.sh 开始
After click on debug button in your IntelliJ Community edition your debug section should open with the following line in its Console area:单击 IntelliJ 社区版中的调试按钮后,您的调试部分应打开,并在其控制台区域中显示以下行:
Connected to the target VM, address: 'localhost:9999', transport: 'socket'连接目标VM,地址:'localhost:9999',传输:'socket'
AmirHd answer is very helpful, but I had one more problem. AmirHd 的回答很有帮助,但我还有一个问题。 When I changed JAVA_OPTS server wouldn't shutdown as in this post: Tomcat failed to shutdown I resolved this by changing当我更改 JAVA_OPTS 服务器时不会像这篇文章中那样关闭: Tomcat failed to shutdown我通过更改解决了这个问题
JAVA_OPTS
to到
CATALINA_OPTS
@AmirHd's answer was very helpful. @AmirHd 的回答非常有帮助。 I'm using Idea Community version and you actually don't need to install any Tomcat plugins at all.我使用的是 Idea Community 版本,您实际上根本不需要安装任何 Tomcat 插件。
catalina.sh
(in Linux) file which is located in the Tomcat bin directory.在位于 Tomcat bin 目录中的catalina.sh
(在 Linux 中)文件的顶部添加以下行。JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
Run
menu.转到创意Run
菜单。 Select Edit Configuration
option.选择Edit Configuration
选项。Remote
from the drop down.单击+号并从下拉列表中选择Remote
。Listening for transport dt_socket at address: 5005
Alt + Shift + F9
or Run -> debug
option.通过按Alt + Shift + F9
或Run -> debug
选项,使用您的 Idea 连接到该端口。No plugins at all.根本没有插件。
put放
set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
line in catalina.bat then open command line in tomcat directory and run在 catalina.bat 中行然后在 tomcat 目录中打开命令行并运行
catalina.bat run
Also note: I had to choose port 5005 because the default one in configuration settings in my IntelliJ was not editable.另请注意:我必须选择端口 5005,因为 IntelliJ 中配置设置中的默认端口不可编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.