工作中经常会遇到需要远程调试java的问题,因此学会使用Jprofiler远程调试很有必要。
首先将jprofiler安装到远程的linux机器上,然后运行jpenable,会弹出下面的提示:
Select a JVM:
org.apache.catalina.startup.Bootstrap start [11463] [1]
test.jar [11425] [2]
这是让选择调试哪一个进程,这里我的程序是test.jar,因此选择2,接下来又有提示:
Please select the profiling mode:
GUI mode (attach with JProfiler GUI) [1, Enter]
Offline mode (use config file to set profiling settings) [2]
要求选择运行模式,这里输入1,接下来让输入监听端口:
Please enter a profiling port
[31757]
8555
You can now use the JProfiler GUI to connect on port 8555
这里面的端口可以自己定义,比如我填一个8555,这样远程调试的时候就输入这个端口就可以了。看到“You can now use the JProfiler GUI to connect on port 8555”表示成功。
接下来就需要在本地的windows下面进行远程调试,首先需要连接到远程的jprofiler。
打开本地的jprofiler,选择ssh远程连接,如下图
然后点击Edit按钮,配置ssh,输入用户名,在Host里面输入远程IP地址,在SSH port里面输入ssh端口,在Profiling port里输入8555端口,点击Start即可开始监控