How to debug when two Web apps need to be loaded?

I have a situation where I have a server application and a client application where they're both Web apps deployed under Tomcat - locally.

Using a URL for the client application, the client calls the server application and does stuff.

All this is working in Tomcat.

Currently the other developers are just using output logs for debugging, but I want to have actual symbolic debugging within Intellij, if possible.

-----------

Where I'm confused is how to go about debugging the server code when the client needs to be loaded too to call it. I want to be able to set a breakpoint in a class on the server code and then have Intellij let me step through the server code when it hits the breakpoint.

However, since the client application also needs to be running in this case, it doesn't seem that I can just "start" the server code in Intellij and then debug -- since the client is not running now (Intellij is running Tomcat for just the server application being deployed).

I thought that this situation might be a case for remote debugging, but if so, I don't see any obvious ways to connect to the Tomcat instance and no real good step by step instructions.

Would appreciate any suggestions on how to handle this so I can debug the server code when the client app's Webpage calls it.

Thanks,

- M

3 comments

I don't expect a problem with debugging of your "server application", have you tried it already?


From java debugger point of view, Tomcat application server + your "server application" + your "client application" makes a single java process to be debugged.


IDEA limits scope of the source code to be debugged (to look for classes with breakpoints) to the modules of artifacts being deployed with the run configuration.
If a run configuration has no artifacts to be deployed -- then scope of the source code to be debugged is the whole project (in this way, the Tomcat itself could be debugged, for instance).

In your case, you may just use Tomcat run configuration (either local or remote) with 2 deployments:
1) "server application" -- as the artifact being build from the project sources with IDEA
2) "client application" -- either as the artifact being build from the project sources with IDEA or as the 'external source' -- an artifact being build outside of IDEA.


With this setup, you should be able to debug "server application" as follows:
1) set breakpoints in the source of the "server application"
2) launch the run configuration in debug mode
3) wait for "server application" and "client application" to be deployed
4) issue a request from the "client application" to the "server application" -> a breakpoint in the "server application" code should be hit.

0

Morkafur wrote:

However, since the client application also needs to be running in this case, it doesn't seem that I can just "start" the server code in Intellij and then debug -- since the client is not running now (Intellij is running Tomcat for just the server application being deployed).

You can simultaneously run and/or debug both the client and server (and even multiple localhost servers assuming they are using different ports) in IDEA. The debug window will have a tab for each. Simply start one, then select the other run/debug configuration and start it. For multiple servers, you can either 1) define a run/debug configuration for each running on a different port or 2) configure the tomcat run/debug configuration to deploy multiple webapps (on the "Deployment" tab in the run/debug configuration dialog) within the same run/debug configuration. Obviously the client needs to be configured appropriately.

Alternatively, you can use the remote debug. After you create the remote run/debug configuration, click on the "Startup/Connection" tab. Then click on "Debug". You will need to copy the JVM command line arguments shown on that tab and pass them to the JVM running Tomcat on startup. One way to do that is to put the options in the CATALINA_OPTS environment variable. (However, if running multiple instances, that variable must be set separately (in a different shell) for each instance.) If you need to debug multiple tomcat instances remotely, you need to have a different port defined for each. This is specified on "Startup/Connection" tab below the text box that shows the JVM arguments. Be sure to copy the arguments after you modify the port.

0

Wow, thanks. I'll give this a try and let you know.

Appreciate your help.

- m

0

Please sign in to leave a comment.