まずEclipse, Apache Tomcat, Subversiveを入れましょう。
sa-struts-tutorialを入手する
プロジェクトのお手本を入手します。zipを解凍したら、Eclipseにプロジェクトをインポートします。
sa-struts-tutorial-1.0.x.zip
http://sastruts.seasar.org/download.html
m2eclipse Plugin
EclipseからMaven2を使うためのプラグインを入れます。
下記のアップデートサイトからプラグインをダウンロードします。
http://m2eclipse.codehaus.org/update/
http://www.atmarkit.co.jp/fjava/rensai3/eclipseplgn11/eclipseplgn11_2.html
Maven Additional Plugin
Mavenで取得したライブラリを WEB-INF/lib に反映するプラグインを入れます。これがあると、EclipseのプロジェクトをTomcatで直接読むことができて便利です。
1)プラグインをインストール。http://www.skirnir.net/eclipse/updates/3.2/
http://d.hatena.ne.jp/yohjizzz/20080616/1213555055
2)プロジェクト→プロパティ→Maven2 Additional で設定を有効にする。
Dynamic Web Projectの作成
メニューの[File]→[Project]でダイアログを開き、[Dynamic Web Project]を選んで次に進みます。ダイアログで実行環境を適切に設定します。参考までに、私の設定を書きます。
Target Runtime | Apache Tomcat v6.0 |
Dynamic Web Module version | 2.5 |
Configuration | Dynamic Web Module: 2.5 Java: 6.0 Runtimes: Apache Tomcat v6.0 |
Context Root | プロジェクト名 |
Content Directory | webapp |
Java Source Directory | src/main/java |
Maven2との連携
プロジェクトを右クリックし、[Maven]→[Enable Dependency Management]をクリックします。とりあえず適当に設定します。
groupId | org.hidetake.slideboard |
artifactId | slideboard |
packaging | war |
version | 0.1 |
生成された pom.xml に次の記述を加えます。バージョンは適当に直してください。
<repositories> <repository> <id>maven.seasar.org</id> <name>The Seasar Foundation Maven2 Repository</name> <url>http://maven.seasar.org/maven2</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.seasar.sastruts</groupId> <artifactId>sa-struts</artifactId> <version>1.0.3</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-ejb_3.0_spec</artifactId> <version>1.0</version> <type>jar</type> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jta_1.1_spec</artifactId> <version>1.1</version> <type>jar</type> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jpa_3.0_spec</artifactId> <version>1.1</version> <type>jar</type> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-interceptor_3.0_spec</artifactId> <version>1.0</version> <type>jar</type> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> <type>jar</type> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> <type>jar</type> </dependency>
build要素に以下を加えておくと、targetフォルダの作成が止まるみたいです。
<sourceDirectory>src/main/java</sourceDirectory> <outputDirectory>webapp/WEB-INF/classes</outputDirectory>
クラスパスの設定
クラスパスを直しましょう。プロジェクトを右クリックして[Build Path]→[Configure Build Path]から。
- Source Folders
- プロジェクト名/src/main/java
- プロジェクト名/src/main/resources
- Default Output Folder
- プロジェクト名/webapp/WEB-INF/classes|
- Libraries
Mavenで取得したライブラリが WEB-INF/lib に同期されるように設定します。プロジェクトを右クリックして[Properties]→[Maven2 Addtional]から。
Enable Additional Maven Nature | チェックを入れる |
Destination | webapp/WEB-INF/lib |
SAStrutsの設定ファイルをコピーする
sa-struts-tutorialプロジェクトから以下のファイルをコピーします。
- src/main/java
- tutorial/action/IndexAction.java
- src/main/resources
- すべてのファイル
- webapp/WEB-INF
- webapp/WEB-INF/view
これで最低限必要なファイルは揃いました。
Tomcatにデプロイする
メニューの[File]→[Other]→[Server]→[Server]でダイアログを開き、適当に環境設定します。サーバを追加したら、メニューの[Window]→[Show View]→[Server]でサーバ一覧を表示します。サーバをダブルクリックすると、設定画面が表示されます
Serve modules without publishing | チェックを入れる |
Publishing | Never publish automatically |
[Modules]タブで[Add Web Module]をクリックし、プロジェクトを指定します。設定を保存し、サーバを右クリックして[Start]で起動します。
動かしてみる
Webブラウザで http://localhost:8080/プロジェクト名/ を開き、動作を確認します。「Welcome to Super Agile Struts Tutorial」という画面が表示されれば成功です。
以上に間違いがあればご指摘ください。