【应用服务 App Service】App Service 中部署Java项目,查看Tomcat配置及上传自定义版本

当在Azure 中部署Java应用时候,通常会遇见下列的问题:

  1. 如何部署一个Java的项目呢?
  2. 部署成功后,怎么来查看Tomcat的服务器信息呢?
  3. 如果Azure提供的默认Tomcat版本的配置跟应用所需要的版本不一致时,如何来自定义Tomcat的版本呢?

适用环境

App Service For Windows

解决方案

对以上的三个问题,可以针对性的参考如下三个文档:

如何在 Web 应用上部署 Spring Boot 项目

https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-howto-deploy-java-spring-boot-project

如何通过 Kudu 查看/修改 Java Tomcat 服务端的配置文件 https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-howto-modify-tomcat-server-profile-with-kudu
如何为 Web 应用配置自定义 Tomcat 环境 https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-howto-configure-custom-tomcat-environment

注:在自定义Tomcat的环境时候,需要特别注意对conf/server.xml的4处修改(端口,连接,IP及路径)

附件一:在使用Azure 默认的Tomcat版本启动Jar包时的Web.config例子如:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="%JAVA_HOME%injava.exe" stdoutLogEnabled ="true" arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%sitewwwrootspringbootsample-1.0.0.jar&quot;">
        </httpPlatform>
    </system.webServer>
</configuration>

附件二:自定义Tomcat版本启动Jar包时的Web.config例子如:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%HOME%sitewwwrootin	omcatinstartup.bat"  arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%sitewwwrootspringbootsample-1.0.0.jar&quot;">
      <environmentVariables>
        <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%" />
        <environmentVariable name="CATALINA_HOME" value="%HOME%sitewwwrootin	omcat" />
        <environmentVariable name="JRE_HOME" value="D:homesitewwwrootinjavajdk1.6.0_45jre6" />  
        <environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>