Maven Jetty Pluginの例

クイックリファレンスのためにMaven Jetty 8.xと9.xのプラグインの例はほとんどありません。
1. Maven Jetty Plugin 9.x
1.1 ‘groupId’は `org.eclipse.jetty`ですが、デフォルトではポート8080、ルートコンテキスト ‘/’で動作します。
pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
</plugin>
Maven Jettyプラグインを実行するには
ターミナル
$ mvn jetty:run
デプロイされたURL:
http://localhost:8080/
実行中のJettyインスタンスを停止するには
ターミナル
$ ctrl + c
1.2コンテキストパスを変更する。
pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/abc</contextPath>
</webApp>
</configuration>
</plugin>
デプロイされたURL:
http://localhost:8080/abc
1.3別のポートを変更します。
pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/abc</contextPath>
</webApp>
<httpConnector>
<port>8888</port>
</httpConnector>
</configuration>
</plugin>
デプロイされたURL:
http://localhost:8888/abc
あるいは、システムプロパティ `jetty.port`を手動で渡すこともできます:
mvn -Djetty.port=8888 jetty:run
1.4 `jetty.xml`の例です。
pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/abc</contextPath>
</webApp>
<jettyXml>jetty.xml</jettyXml>
</configuration>
</plugin>
jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure__9__3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New id="httpConnector" class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server"/></Arg>
<Set name="host"><Property name="jetty.http.host" deprecated="jetty.host"/></Set>
<Set name="port"><Property name="jetty.http.port" deprecated="jetty.port" default="1234"/></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" deprecated="http.timeout" default="30000"/></Set>
</New>
</Arg>
</Call>
</Configure>
デプロイされたURL:http://localhost:1234/abc
-
注** 詳細http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html[Jetty Maven Plugin 9.xの例]
2. Maven Jetty Plugin 8.x
2.1 ‘groupId’は `org.mortbay.jetty`で、デフォルトではポート8080、ルートコンテキスト ‘/’で動作します。
pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
</plugin>
2.2異なるコンテキストパスを変更し、変更を確認して自動的にホット再デプロイする秒数を設定します。
pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/abc</contextPath>
</webApp>
</configuration>
</plugin>
デプロイされたURL:
http://localhost:8080/abc
2.3起動する別のポートを変更します。
pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/abc</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8888</port>
</connector>
</connectors>
</configuration>
</plugin>
デプロイされたURL:
http://localhost:8888/abc
あるいは、システムプロパティ `jetty.port`を手動で渡すこともできます。
mvn -Djetty.port=8888 jetty:run
__P.Sクラス `SelectChannelConnector`がデフォルトのJettyコネクターです。
-
注** + More
https://wiki.eclipse.org/Jetty/Feature/Jetty
Maven
Plugin[Jetty Maven Plugin 8.xの例]
参考文献
-
http://en.wikipedia.org/wiki/Jetty
%28web
server%29[Wikipedia:Jetty
Maven Plugin 9.x]。
https://wiki.eclipse.org/Jetty/Feature/Jetty
Maven
Plugin[Jetty Maven
プラグイン8.x]