java 使用 Intellij Idea 进行远程调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11646763/
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
Remote Debugging with Intellij Idea
提问by Izza
I came to know of the remote debugging procedure under Idea recently. What I do is copy the configuration of remote debug under Run | Debug Configuration in Idea to the command line java execution parameters. The actual command line parameters are:
最近才知道Idea下的远程调试程序。我做的是复制Run下的remote debug的配置 | 在idea中调试配置到命令行java执行参数。实际的命令行参数是:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
If it is a script, I add these commands to it. By doing so, the command line displays the message:
如果它是一个脚本,我将这些命令添加到它。通过这样做,命令行显示消息:
Listening for transport dt_socket at address: 8000
So the debugging can happen using the local source code. However, I don't properly understand how remote debugging work. Anyone who knows how remote debugging actually works, please give me an explanation.
因此可以使用本地源代码进行调试。但是,我没有正确理解远程调试的工作原理。任何知道远程调试实际工作原理的人,请给我一个解释。
Thank you!
谢谢!
回答by CrazyCoder
Remote debugging means that you can run your Java code anywhere, either on the local or remote machine. When it's running in the debug mode, you can connect to it from the IDE using TCP network connection and perform debugging. IDE needs to have the source code for the running classes so that you can place breakpoints inside this code and perform stepping, inspecting variables, etc.
远程调试意味着您可以在本地或远程机器上的任何地方运行 Java 代码。当它在调试模式下运行时,您可以使用 TCP 网络连接从 IDE 连接到它并执行调试。IDE 需要具有运行类的源代码,以便您可以在此代码中放置断点并执行步进、检查变量等。
If you are interested in technical details, refer to the JPDA documentation.
如果您对技术细节感兴趣,请参阅JPDA 文档。
回答by Ashish Yadav
Consider a scenario where you want to fix something in your application but your application only can run over a server machine because of other dependencies. That is where Remote Debugging come into picture. You Just connect the sever by providing the hostname and port and connect it with your respective environment.
考虑一个场景,您想修复应用程序中的某些内容,但由于其他依赖关系,您的应用程序只能在服务器机器上运行。这就是远程调试出现的地方。您只需通过提供主机名和端口来连接服务器,并将其与您各自的环境连接。
How It works:
怎么运行的:
- Application to be debugged will attach a socket to itself and then will start listening debug instructions.
- Debugger will bind itself to that socket and then send instructions.
- 要调试的应用程序将为其自身附加一个套接字,然后将开始侦听调试指令。
- 调试器会将自身绑定到该套接字,然后发送指令。
回答by BSrinivas
This is best way to test your code which are in different environment .
这是测试您在不同环境中的代码的最佳方式。
we need to have below points for sure before you are using remote debug .
在您使用远程调试之前,我们需要确定以下几点。
- we are using JBOSS in our servers.
configure - JBOSS_HOME/bin/run.conf JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
now add the server IP and port number into the intellij remote debugging . 4.your should have the latest version of the project in local that is in synch with the server else debug will not be allowed.
- you need to start the intellij server for the project .
- Then start the remote debug .
- place a debug point in local and when we start testing in the server , when it hits the debug point it will stop and wait untill you process it .
- 我们在我们的服务器中使用 JBOSS。
配置 - JBOSS_HOME/bin/run.conf JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
现在将服务器IP和端口号添加到intellij远程调试中。4.您应该在本地拥有与服务器同步的最新版本的项目,否则将不允许调试。
- 您需要为项目启动 Intellij 服务器。
- 然后启动远程调试。
- 在本地放置一个调试点,当我们在服务器中开始测试时,当它到达调试点时,它将停止并等待您处理它。
The other point is , it will hold all the request in the queue and will not allow anyone to go through the break point which may stop other users to test it .
另一点是,它会将所有请求保留在队列中,并且不允许任何人通过可能会阻止其他用户对其进行测试的断点。