Microsoft Azure websites supports running Java Web Applications. This blog describes the support for remote debugging your Java Web Applications on Microsoft Azure Websites.
Prerequisites
- Azure website with a Java Web Application with a web.config that enables JVM debug server.
- Enable websockets on your azure web site.
- When using ZULU JDK on Azure Webapp, please change bitness of your webapp to 64bit.
- JDWP compatible debugger like Eclipse/Netbeans.
- DebugSession Client application (your debugger will connect to this client application).
- Modify Eclipse Remote Debugging Timeout. Open Eclipse and Go to -> Windows -> Preferences -> Debug ->
- Increase Debugger Timeout (ms) and Launch timeout (ms) to 120000.
If you selected Zulu JDK, change the bitness of your webapp to 64bit. If not, the remote debugging tool cannot connect to your webapp.
If you already have web.config in your azure website site\wwwroot, add the following line to the JAVA_OPTS environment variable. -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:%HTTP_PLATFORM_DEBUG_PORT% As shown below:
<httpPlatform>
<environmentVariables>
<environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:%HTTP_PLATFORM_DEBUG_PORT%"/>
</environmentVariables>
</httpPlatform>
NOTE: %HTTP_PLATFORM_DEBUG_PORT% is a special placeholder which will be replaced with a port internally generated by the HttpPlatformHandler module.
Restart your azure website after editing the web.config.
If you don’t have a web.config, you will need to create one. Please see references section for links to sample web.config.
Download the DebugSession client application from https://github.com/Azure/azure-websites-java-remote-debugging/releases
On your local machine, run DebugSession.bat (DebugSession.sh on linux) as shown below.
C:\JDebug\bin>DebugSession.bat
usage: org.azure.waws.DebugSessionMain
-a,--affinity <arg> affinity cookie value (optional)
-p,--port <arg> local port (required)
-s,--server <arg> server (required)
-t,--auto restart client application automatically on disconnect/error.
-u,--user <arg> username (required iff password is specified)
-w,--pass <arg> password (optional)
Example: DebugSession.bat –p 8000 –s yoursite.scm.azurewebsites.net –u deploymentUserName –w deploymentPassword –t
You could specify the Affinity cookie value to hit a specific instance of your site if your site is configured to run on multiple workers and you want to debug a specific instance.
When connecting to your azure app service scm endpoint, please use credentials associated with publishMethod="MSDeploy". To get this, get the publish profile by doing the following:
In the Azure portal, click App Service > <your_app> > Overview.
Click ...More > Get publish profile, and download starts for a .PublishSettings file. Use the username and password associated with the "MSDeploy" publishMethod.
Connect eclipse debugger to your DebugSession
Click “Remote Java Application”, enter the port on which you started DebugSession.bat and then click ‘Debug’.
References