I'm debugging an application on a remote server running JBoss using Eclipse. My particular problem is a NullPointerException
in a JSP. The JSP has too much Java code inside scriptlets but, unfortunately refactoring is not going to be an option. Finding the line that throws the NullPointerException
has been incredibly challenging and I'm getting stuck.
我正在使用Eclipse在运行JBoss的远程服务器上调试应用程序。我的特殊问题是JSP中的NullPointerException。 JSP在scriptlet中有太多的Java代码,但不幸的是,重构不是一个选择。找到抛出NullPointerException的行非常具有挑战性,而且我遇到了困难。
How can I debug this JSP remotely to find the line of the scriplet throwing the NullPointerException
?
如何远程调试此JSP以查找抛出NullPointerException的scriplet行?
I ended up finding the problem by commenting out lines of the JSP until I isolated the issue. Tedious but, it worked.
我最后通过注释掉JSP的行来找到问题,直到我解决了这个问题。单调乏味但有效。
2 个解决方案
#1
You can enable remote debugging on some application servers by adding something like this
您可以通过添加类似的东西在某些应用程序服务器上启用远程调试
-Xdebug -Xrunjdwp:transport=dt_socket,address=5001,server=y,suspend=n
to the command line. Then, in your IDE, connect to port 5001 for remote debugging. This page has some examples for various application servers.
到命令行。然后,在IDE中,连接到端口5001以进行远程调试。此页面包含各种应用程序服务器的示例。
I find that debugging JSPs can sometimes be done easily if you have the java source for the compiled JSPs. Check your application server's manual for JSP compilation or pre-compile your JSPs and save the .java files; then use these files as the source for the debugger.
我发现如果你有编译JSP的java源代码,调试JSP有时可以很容易地完成。检查应用程序服务器的JSP编译手册或预编译JSP并保存.java文件;然后使用这些文件作为调试器的源。
#2
Generally you will be able to find the error on the server log. Since you are running it on a remote server, go to that machine and check the log. It should point out the error.
通常,您将能够在服务器日志中找到错误。由于您是在远程服务器上运行它,请转到该计算机并检查日志。它应该指出错误。
I find it easier to debug if I am running a local version of the site as I can monitor the server log through eclipse in real time. Perhaps it would be worth it to set up a local copy you can develop with and then just deploy to the remote server when you have fully debugged the code.
如果我运行本地版本的站点,我发现调试更容易,因为我可以实时监视eclipse中的服务器日志。也许值得设置一个可以开发的本地副本,然后在完全调试代码后部署到远程服务器。
Hope this helps.
希望这可以帮助。
#1
You can enable remote debugging on some application servers by adding something like this
您可以通过添加类似的东西在某些应用程序服务器上启用远程调试
-Xdebug -Xrunjdwp:transport=dt_socket,address=5001,server=y,suspend=n
to the command line. Then, in your IDE, connect to port 5001 for remote debugging. This page has some examples for various application servers.
到命令行。然后,在IDE中,连接到端口5001以进行远程调试。此页面包含各种应用程序服务器的示例。
I find that debugging JSPs can sometimes be done easily if you have the java source for the compiled JSPs. Check your application server's manual for JSP compilation or pre-compile your JSPs and save the .java files; then use these files as the source for the debugger.
我发现如果你有编译JSP的java源代码,调试JSP有时可以很容易地完成。检查应用程序服务器的JSP编译手册或预编译JSP并保存.java文件;然后使用这些文件作为调试器的源。
#2
Generally you will be able to find the error on the server log. Since you are running it on a remote server, go to that machine and check the log. It should point out the error.
通常,您将能够在服务器日志中找到错误。由于您是在远程服务器上运行它,请转到该计算机并检查日志。它应该指出错误。
I find it easier to debug if I am running a local version of the site as I can monitor the server log through eclipse in real time. Perhaps it would be worth it to set up a local copy you can develop with and then just deploy to the remote server when you have fully debugged the code.
如果我运行本地版本的站点,我发现调试更容易,因为我可以实时监视eclipse中的服务器日志。也许值得设置一个可以开发的本地副本,然后在完全调试代码后部署到远程服务器。
Hope this helps.
希望这可以帮助。