For many developers, debugging a web application simply means looking at the logs and trying to figure out what went wrong. Fortunately, there is an easier way. You can debug a web/JEE application the same way you debug a JSE or JME application.
With today's IDEs you can also debug web/jee applications step by step, while the application is deployed to an application server like JBoss. The following trick works with JBoss application server, please contribute for other application servers.
OK, here is the trick. Open %JBOSS_HOME%/bin/run.bat (Windows) or $JBOSS_HOME/bin/run.sh (Linux) and uncomment the line that contains the port 8787, i.e. this line (by simply deleting the rem word in front):
With today's IDEs you can also debug web/jee applications step by step, while the application is deployed to an application server like JBoss. The following trick works with JBoss application server, please contribute for other application servers.
OK, here is the trick. Open %JBOSS_HOME%/bin/run.bat (Windows) or $JBOSS_HOME/bin/run.sh (Linux) and uncomment the line that contains the port 8787, i.e. this line (by simply deleting the rem word in front):
rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%
If you cannot find the line in run.sh, try $JBOSS_HOME/bin/run.conf.
In your eclipse environment, click on the arrow next to the Debug button and select Debug... Select Remote Java Application and press the New button to create a new configuration of this type.
In the Connect tab, browse your web / jee eclipse project, leave the connection type to Standard (Socket Attach) and enter the host name (localhost if it is local) but modify the port to 8787 (this is JBoss' debugging port). In the Source tab you may wish to add any dependent projects. Click on Apply. That's it.
In your eclipse environment, click on the arrow next to the Debug button and select Debug... Select Remote Java Application and press the New button to create a new configuration of this type.
In the Connect tab, browse your web / jee eclipse project, leave the connection type to Standard (Socket Attach) and enter the host name (localhost if it is local) but modify the port to 8787 (this is JBoss' debugging port). In the Source tab you may wish to add any dependent projects. Click on Apply. That's it.
Now all you need to do is start your JBoss application server, deploy before or after your war or ear file. The application server stops waiting for someone to listen to port 8787. Click on Debug or select the above configuration in the Debug window, and voila, JBoss continues starting up.
Set your breakpoints etc. enjoy!
P.S. Netbeans has very good debugging integration with most of the application servers. If your application server is not listed in its list of available application servers, simply define it under Tools --> Server.
References
Set your breakpoints etc. enjoy!
P.S. Netbeans has very good debugging integration with most of the application servers. If your application server is not listed in its list of available application servers, simply define it under Tools --> Server.
References