1. 程式人生 > 實用技巧 >【應用服務 App Service】App Service 中部署Java專案,檢視Tomcat配置及上傳自定義版本

【應用服務 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%\bin\java.exe" stdoutLogEnabled ="true" arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\springbootsample-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%\site\wwwroot\bin\tomcat\bin\startup.bat"  arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\springbootsample-1.0.0.jar&quot;">
      <environmentVariables>
        <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%" />
        <environmentVariable name="CATALINA_HOME" value="%HOME%\site\wwwroot\bin\tomcat" />
        <environmentVariable name="JRE_HOME" value="D:\home\site\wwwroot\bin\java\jdk1.6.0_45\jre6" />  
        <environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>