3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Azure WebAppsのJavaアプリケーションをリモートデバッグ

Posted at

tl;dr

ここの作業を行うだけです。

手順

WebAppsの設定でWebSocketを有効化

AzureポータルからWebAppのアプリケーション設定を開き、「Webソケット」をオンにしておきます。

2018-04-05-21-05-49.png

デバッグ時にWebSocketを通してリモートとやり取りを行うため、この設定が必要です。

App Service上に site\wwwroot\web.config を作る。

WebAppの裏で暗躍しているkuduにアクセスして作るのが楽です。

kuduはざっくりいえば、AppServiceを裏で支えるソフトウェアで、デプロイの制御やWebJobsの動作等の面倒を見たり、開発に便利なブラウザから利用できるコンソールも提供しています。

  • ブラウザを開き、https://YOURAPP.scm.azurewebsites.net/DebugConsole にアクセス
    • (※YOURAPPはWebAppリソース作成時の名前になる。公開用URLの間にscmが入っただけと覚えるとよい。)
  • sitewwwrootに移動
  • [+]アイコンから「New File」でweb.configファイルを作成。
    • %programfiles(x86)% の箇所は、32bitの場合で、64bitの場合は異なる。(Free等格安プランだと32bit)
    • apache-tomcat-8.0.46の箇所は、tomcatのバージョンで変わる。
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httppPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        
        <httpPlatform processPath="%programfiles(x86)%\apache-tomcat-8.0.46\bin\startup.bat">
            <environmentVariables>
                <environmentVariable name="CATALINA_HOME" value="%programfiles(x86)%\apache-tomcat-8.0.46"/>
                <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%"/>
                <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%"/>
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>

アプリケーションの再起動

ポータル上から再起動を行う。

再起動後、1度アクセスしてJavaプロセスが動いている状態にしておく。kudu上のProcess Explorerで確認可能

WebApp側の作業はここまで。

DebugSessionクライアントの起動

ここからはローカルマシン上の作業。

https://github.com/Azure/azure-websites-java-remote-debugging/releases からDebugSessionクライアントをダウンロード。

binの中にあるDebugSessin.batに以下の引数を与えて起動。環境変数のJAVA_HOMEを設定しておく。

-s-u-wの値は適宜置き換えてください。

DebugSession.bat ^
  --auto ^
  -p 8000 ^
  -s YOURAPP.scm.azurewebsites.net ^
  -u $YOURAPP ^
  -w ****

情報: Waiting for debugger to connect on 8000 ...

・・・と出ていたら、準備はOK。

なお、接続情報(PublishURL/User/Pass)はAzure CLIならaz webapp deployment list-publishing-profiles ...あたりで得られるMSDeployの値を使えばOK

デバッガを起動

後は、Eclipse上のデバッガ等からDebugSessionクライアント(localhost:8080)に接続することで、リモートデバッグが行えるようになる。

ただ、リモートなので動作がもっさりしている。(freeプランだったからかもしれない。)

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?