normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

JavaEE の実行環境を Microsoft Azure の Web サイト上で稼働させる

新年初ポストは Web サイトと JavaEE について言及させていただきたい。良い子の諸君は JavaEE といえば GlassFish, WebSphere, JBoss AS, WebLogic (それぞれ正式名称が違うのはご容赦頂きたい)を想像すると思うが、Java EE6 から導入されたWeb Profile の実装である TomcatEE を Web サイト上で稼働させることで JavaEE の機能を利用することが可能となることはご存知だと思う。
今回は Tomcat EE を Web サイト上で稼働させてみるが、2015年1月時点での最新版である TomcatEE 1.7.1 の実装は以下となっているので、おおよそ JavaEE6 の機能が稼働すると考えてよいだろう。

Web サイト上での Tomcat EE の稼働

Tomcat 自体は Web サイトにバンドルされているが、まずは Web サイトのギャラリーから Tomcat を選択して Web サイトを作成する(こちらで web.config が作成されるため、TomcatEE の設定を実施しやすくなる)。
f:id:waritohutsu:20150104010257p:plain
次に、Kudu に接続して以下のコマンドを実行して Web サイト上に Tomcat EE を展開する( TomcatEE の URL はバージョン次第で変えること )。

D:\home\site\wwwroot>dir
 Volume in drive D is Windows
 Volume Serial Number is 746D-E3BB

 Directory of D:\home\site\wwwroot

01/02/2015  04:10 PM    <DIR>          .
01/02/2015  04:10 PM    <DIR>          ..
01/02/2015  04:12 PM    <DIR>          bin
01/02/2015  04:13 PM             4,828 web.config
               1 File(s)          4,828 bytes
               3 Dir(s)     767,229,952 bytes free

D:\home\site\wwwroot>cd bin

D:\home\site\wwwroot\bin>curl -O http://ftp.riken.jp/net/apache/tomee/tomee-1.7.1/apache-tomee-1.7.1-plus.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 41.4M  100 41.4M    0     0  11.0M      0  0:00:03  0:00:03 --:--:-- 11.1M

D:\home\site\wwwroot\bin>unzip apache-tomee-1.7.1-plus.zip 

次に、D:\home\site\wwwroot\web.config を以下のように編集する。CATALINA_HOME を編集している点に注目してほしい。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" 
                 modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="dd:\home\site\wwwroot\bin\apache-tomee-plus-1.7.1\bin\startup.bat">
            <environmentVariables>
                <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%" />
                <environmentVariable name="CATALINA_HOME" value="d:\home\site\wwwroot\bin\apache-tomee-plus-1.7.1" />                
                <environmentVariable name="JAVA_OPTS" 	  value="-Djava.net.preferIPv4Stack=true" />
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>

更に、D:\home\site\wwwroot\bin\apache-tomee-plus-1.7.1\conf\server.xml を以下のように編集する(抜粋しているので注意してほしい)。Connector タグの port 属性を 8080 から #{port.http} に編集している点に注意してほしい。

        <Connector port="${port.http}" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
        <!-- A "Connector" using the shared thread pool-->

ここで Azure の管理ポータルより当該 Web サイトを再起動する。再起動後、Web サイトにアクセスすることで TomcatEE となっていることが確認できる。
f:id:waritohutsu:20150104010332p:plain