问题描述

在Web App wwwroot (Windows系统中)根目录下如何部署一个jar包和一个text文件,让两个文件都能被访问?

 

解决办法

Jar包和Text文件都分别放置在两个单独的文件夹中,并且在各自的文件夹中添加web.config来指明启动方式。

第一步:通过 App Service 门户配置页面,添加两个文件夹 test 和test1

【Azure 应用服务】App Service 部署txt静态文件和Jar包在不同目录中的解决办法_Azure 环境

第二步:将txt文件放在 site\wwwroot\test 文件夹下,添加一个web.config文件来访问静态文件

web.config内容如下:

<?xml version="1.0"?>  
<configuration>
<system.webServer>
<handlers>
<clear />
<add
name="StaticFile"
path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>

第三步:将jar包放在 site\wwwroot\test1 文件夹下,添加一个web.config文件,用于启动Jar包

web.config内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<!-web app的java.exe路径和jar包存放的路径->
<httpPlatform processPath="C:\Program Files\Java\zulu11.48.21-jre11.0.11-win_x64\bin\java.exe" arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\test1\test.jar"" >
</httpPlatform>
</system.webServer>
</configuration>

第四步:部署后,在Kudu中查看文件结构如下

【Azure 应用服务】App Service 部署txt静态文件和Jar包在不同目录中的解决办法_Azure 环境_02

第五步:重启站点,通过默认URL加\test,\test1分别访问test及jar文件内容

 

 

参考资料

Java HttpPlatformHandler Configuration Examples :​​https://docs.microsoft.com/zh-cn/iis/extensions/httpplatformhandler/httpplatformhandler-configuration-reference#httpplatformhandler-configuration-examples​

 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!