jetty-maven-plugin で Jetty 9 な HTTPS サーバを設定してみます.
基本的に,Configuring the Jetty Maven Plugin http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html の Configuring a Https Connector で説明されている通りです.
Jetty 9.1.2
Oracle Java SE 7u51
Eclipse Kepler (4.3.1) SR1 (Eclipse IDE for Java EE Developers)
jetty-maven-plugin
OS X 10.9.1
Keystore
サーバ秘密鍵とサーバ証明書を収めた Keystore を作成します.
作成例はこちら.
Jetty 9 のための Keystore
Maven プロジェクトの作成
Maven プロジェクトを作成し,jetty-maven-plugin を適用させます.
やり方は例えば,
[Jetty 9.1] Eclipse + jetty-maven-plugin
設定用 XML ファイル
http://download.eclipse.org/jetty/ から Jetty をダウンロードし,その中の設定ファイルをテンプレートとして使用します.
Jetty 9.1.2 をダウンロードして解凍,展開します.
etc フォルダ下の jetty.xml, jetty-ssl.xml, jetty-https.xml を Eclipse のプロジェクト下にコピーします.
cd /path/to/jetty9/etc cp jetty.xml /path/to/workspace/project/ cp jetty-ssl.xml /path/to/workspace/project/ cp jetty-https.xml /path/to/workspace/project/
jetty.xml
特に変更する箇所はありません.
jetty-ssl.xml
Keystore の場所とパスワードは,Jetty 9 のための Keystore で設定した内容です.
... <Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory"> <Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="src/main/resources/keystore"/></Set> <Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="stostosto"/></Set> <Set name="KeyManagerPassword"><Property name="jetty.keymanager.password" default="expexpexp"/></Set> <Set name="EndpointIdentificationAlgorithm"></Set> <Set name="ExcludeCipherSuites"> ...
実際は,テンプレート同様に,パスワードは平文ではなくハッシュ化したほうが良いです.
jetty-https.xml
HTTPS で使用する TCP ポート番号を設定します.jetty.xml の内容よりも jetty-https.xml の内容の方が優先されるようです.
... <Set name="host"><Property name="jetty.host" /></Set> <Set name="port"><Property name="https.port" default="9443" /></Set> <Set name="idleTimeout"><Property name="https.timeout" default="30000"/></Set> ...
pom.xml
pom.xml の jetty-maven-plugin の所に,カンマ区切りで設定用 xml ファイルを記載しておきます.カンマと XML ファイルの間にスペースがあるとエラーになるようです.
... <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.1.2.v20140210</version> <configuration> <jettyXml>jetty.xml,jetty-ssl.xml,jetty-https.xml</jettyXml> </configuration> </plugin> ...
起動
goal jetty:run を実行し,設定ファイルが読み込まれ.Jetty が起動することを確認します.
2014-02-23 21:36:07.099:INFO:oejs.ServerConnector:main: Started ServerConnector@6c2fc81d{SSL-http/1.1}{0.0.0.0:9443} [INFO] Started Jetty Server