perlでTomcatを起動させるコード
今は試行錯誤中なのですが、そのうち複数のTomcatにアプリケーションをデプロイさせる方法を書く予定です。
その前段階として、Tomcatを操作するperlのコードを今回は掲載しておきます。
下記の例はjsp-examplesというアプリケーションを起動させるコードです。
#!c:/perl/bin/perl use LWP::UserAgent; use HTTP::Request::Common; use strict; use warnings; my $url = 'http://localhost:8080/manager/start?path=/jsp-examples'; my $ua = new LWP::UserAgent; my $username = 'admin'; my $password = 'tomcat'; my $request = HTTP::Request->new(GET => $url); $request->authorization_basic($username, $password); my $response = $ua->request($request); if ($response->is_success) { print $response->content; } else { print 'Error'; }
以下の記述でブラウザから行うのと同じ認証を行っています。
$request->authorization_basic($username, $password);