java 如何在 Linux 中使用 IntelliJ 社区(免费)版本在本地调试 Tomcat 7.x/8.x webapp?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27655978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug a Tomcat 7.x/8.x webapp locally with IntelliJ Community (free) version in Linux?
提问by AmirHd
I understand that this is possible to do with the Ultimate Edition, but is there a way to debug these applications locally in the Community Edition?
我知道这可能与 Ultimate Edition 相关,但是有没有办法在 Community Edition 中本地调试这些应用程序?
回答by AmirHd
History
历史
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. It is possible to get your IntelliJ Community version to do the same thing for you with a little bit of extra settings.
如果您使用过 IntelliJ Ultimate 版本,您就会看到可以添加 Tomcat 配置,您可以在其中从 IntelliJ 中调试或运行 Tomcat 容器。通过一些额外的设置,可以让您的 IntelliJ 社区版本为您做同样的事情。
Relevant concepts
相关概念
Tomcat JMX
雄猫JMX
This is a remote monitoring and management tool for Tomcat. JMX related settings is not needed to enable your debugging. Although it can be useful for monitoring purposes through JConsole (read more).
这是Tomcat的远程监控管理工具。启用调试不需要 JMX 相关设置。尽管它对于通过 JConsole 进行监控很有用(阅读更多)。
Different ports
不同的端口
You instance of Tomcat must be already up and running for the Community version to be able to attach itself to the Tomcat process. 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 进程。虽然您的 tomcat 将在一个端口上运行(Tomcat 默认为 8080),但您还需要为调试器设置另一个端口以将其自身附加到您正在运行的 Tomcat 版本(在我们的示例中为 9999)。
Settings
设置
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.
请按照更改顺序。
Tomcat side related changes
Tomcat端相关变化
Stop your Tomcat if it is running in your Tomcat bin folder through:
./shutdown
or./catalina stop
Add the following line to your catalina.sh file under the commented JAVA_OPTS set statement:
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999"
如果 Tomcat 在 Tomcat bin 文件夹中运行,请通过以下方式停止 Tomcat:
./shutdown
或./catalina stop
将以下行添加到 catalina.sh 文件中注释的 JAVA_OPTS set 语句下:
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
. However, it is possible to useCATALINA_OPTS
in a similar manner to enable the debugging.
提示:我已经使用
JAVA_OPTS
没有CATALINA_OPTS
在catalina.sh建议最好是用作意见JAVA_OPTS
。但是,可以以CATALINA_OPTS
类似的方式使用以启用调试。
- Start Tomcat:
- 启动Tomcat:
./catalina.sh start
./catalina.sh 开始
IntelliJ related changes
IntelliJ 相关变化
Result
结果
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'
Relevant posts and links
相关帖子和链接
- Remote debugging with Tomcat (7) and Intellij(Very useful for Window only though)
- IntelliJ and Tomcat.. Howto..?(Misleading as it's old)
- IntelliJ ultimate and community version setups(Helpful but over complicated)
- IntelliJ IDEA 14.0.0 Web Help/Run/Debug Configuration: Tomcat(Somewhat useful)
- Debugging with Tomcat and Intellij Community Edition(Old and incomplete)
- 使用 Tomcat (7) 和 Intellij 进行远程调试(虽然仅对 Window 非常有用)
- IntelliJ 和 Tomcat ......如何......?(误导,因为它是旧的)
- IntelliJ 终极版和社区版设置(有用但过于复杂)
- IntelliJ IDEA 14.0.0 Web 帮助/运行/调试配置:Tomcat(有点有用)
- 使用 Tomcat 和 Intellij 社区版进行调试(旧的和不完整的)
回答by Amadeusz Iwanowski
AmirHd answer is very helpful, but I had one more problem. When I changed JAVA_OPTS server wouldn't shutdown as in this post: Tomcat failed to shutdownI resolved this by changing
AmirHd 的回答很有帮助,但我还有一个问题。当我更改 JAVA_OPTS 服务器时不会像这篇文章中那样关闭: Tomcat failed to shutdown我通过更改解决了这个问题
JAVA_OPTS
to
到
CATALINA_OPTS
回答by JanBrus
For Windows users
对于 Windows 用户
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 中配置设置中的默认端口不可编辑。
回答by Nipun Thathsara
@AmirHd's answer was very helpful. I'm using Idea Community version and you actually don't need to install any Tomcat plugins at all.
@AmirHd 的回答非常有帮助。我使用的是 Idea Community 版本,您实际上根本不需要安装任何 Tomcat 插件。
- Add below line at the top of your
catalina.sh
(in Linux) file which is located in the Tomcat bin directory.
- 在
catalina.sh
位于 Tomcat bin 目录中的(在 Linux 中)文件的顶部添加以下行。
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
- Go to Idea
Run
menu. SelectEdit Configuration
option. - Click on the +sign and select
Remote
from the drop down. - For that remote debugger, configure your Tomcat debug host and port. (Localhost, 5005) as below and save.
- Start your Tomcat. (You will see it's in the debugging mode by the below log line.)
- 转到创意
Run
菜单。选择Edit Configuration
选项。 - 单击+号并
Remote
从下拉列表中选择。 - 对于该远程调试器,请配置 Tomcat 调试主机和端口。(Localhost, 5005) 如下所示并保存。
- 启动你的Tomcat。(您将在下面的日志行中看到它处于调试模式。)
Listening for transport dt_socket at address: 5005
- Connect to that port using your Idea by pressing
Alt + Shift + F9
orRun -> debug
option.
- 按
Alt + Shift + F9
或Run -> debug
选项使用您的 Idea 连接到该端口。
No plugins at all.
根本没有插件。