Spring-MVC/ステップ・バイ・ステップ

2008/03/14からのアクセス回数 8827

EclipseでWebアプリケーションを作成する場合、ソースを変更するたびに

の一連の作業をしなくてはなりません。ここでは、これらの作業をjettyプラグインを使って 簡単に実行する方法を紹介します。

jettyプラグインの設定

jettyプラグインを使うためには、pomファイルのbuildのpluginsに以下のpluginタグを 追加します。

	<plugins>
	  <plugin>
	    <groupId>org.mortbay.jetty</groupId>
	    <artifactId>maven-jetty-plugin</artifactId>
	    <version>6.1.7</version>
	  </plugin>		
	</plugins>

jettyの起動

mavenを使ってjettyを起動するには以下のように入力します。

$ mvn jetty:run

すると、リソースの配備、コンパイル、テストリソースの配備、テストのコンパイルを実行し、jettyを 起動します。 コンソールには以下のように出力されます。

take-2:~/tmp/mvc-convention take$ mvn jetty:run
Listening for transport dt_socket at address: 1044
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO] ------------------------------------------------------------------------
[INFO] Building mvc-convention Maven Webapp
[INFO]    task-segment: [jetty:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [jetty:run]
[INFO] Configuring Jetty for project: mvc-convention Maven Webapp
[INFO] Webapp source directory = /Users/take/tmp/mvc-convention/src/main/webapp
[INFO] web.xml file = /Users/take/tmp/mvc-convention/src/main/webapp/WEB-INF/web.xml
[INFO] Classes = /Users/take/tmp/mvc-convention/target/classes
2008-03-14 15:32:09.951::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /mvc-convention
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] Webapp directory = /Users/take/tmp/mvc-convention/src/main/webapp
[INFO] Starting jetty 6.1.7 ...
2008-03-14 15:32:09.188::INFO:  jetty-6.1.7
2008-03-14 15:32:10.755::INFO:  No Transaction manager found - if your webapp requires one, please configure one.
2008-03-14 15:32:11.980::INFO:  Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

ブラウザーでの確認

mavenプロジェクトの作成 で作成したプロジェクトをブラウザーで確認します。

ブラウザーで以下のように入力すると

http://localhost:8080/mvc-convention/

Hello World!画面が表示します。

hello.jpg

jettyの停止

jettyを停止するには、コンソールからCtrl-C(コントロールキーとCを同時に押す)を入力します。

コメント

この記事は、

選択肢 投票
おもしろかった 0  
そうでもない 0  
わかりずらい 0  

皆様のご意見、ご希望をお待ちしております。



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
SmartDoc