When you want to run Java/Tomcat based web applications in Azure AppServices, you simply enable Java and Tomcat i Application Settings. If you deploy a WAR-file, web site will pick it up and the app will be available. But how do you modify the Tomcat configuration if you needed?
Lets say you have a memory hungry Java app that starts emitting errors that you suspect is due to Tomcat being low on memory. That can be fixed setting the “-X” argument in the JAVA_OPTS environment variable before launching Java/Tomcat. How do you do that in Azure AppServices?
Where Tomcat lives in AppServices
Apache Tomcat exists on the D:-drive in the file system of your underlying AppServices machines. With the built in Console, you can navigate there an view the file content by typing it to the output window. As you can see, the various versions of Tomcat that is supported and selectable in the drop-down box (above) are preinstalled in D:\Program Files (x86)\apache-tomcat-8.x.y\bin. The startup.bat and catalina.bat contains instructions for how to startup Tomcat.
If you want to snoop in the files with an editor, you have to copy them to your website’s folder and download them there via ftp. There is just on problem – there is no way to copy them back, so you can forget about edit and upload them. And since AppServices is PaaS and not an IaaS VM, you can’t start modifying the VMs environment either.
Modifying Tomcat via IIS
In order to modify Tomcat’s environment when it starts, you actually have to create a Web.Config file in the website’s root folder (or edit it if it already exists). Through using the IIS HttpPlatform handler we can point to the startup.bat file that bootstraps Tomcat and also modify the environment it is running in (see reference about HttpPlatform handler for details).
<?xml version="1.0" encoding="UTF-8"?>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
<httpPlatform processPath="%AZURE_TOMCAT85_HOME%\bin\startup.bat" arguments="start">
<environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%" />
<environmentVariable name="CATALINA_HOME" value="%AZURE_TOMCAT85_HOME%" />
value="-Djava.net.preferIPv4Stack=true -Xmx1024000000" />
To upload it via ftp to your AppService website, you first have to set the FTP Deployment Credentials.
And after that use your ftp client program, like FileZilla, and connect to the website. The ftp server name can be found in the Overview section in portal.azure.com for your AppService website. Not that you connect with the userid being app-service-name\userid, ie cljungjava01\johnwayne in my case.
Upload the Web.config file to your wwwroot directory and restart the AppService webapp if it already was started.
There is always a solution to fix things and even though Azure AppServices is a PaaS environment that don’t let you edit the surrounding environment or preset installations, you can tweak then in other ways. If you need to modify Tomcat’s environment, you can do it via the HttpPlatform handler that IIS has. Specifying JAVA_OPTS settings there will be merged in to what catalina.bat prepares before launching Tomcat.