WEBアプリをデプロイする †
(1) EARの構成
xxxxx.ear
├ META-INF
| └ application.xml
├ xxxxx.jar (EJB用のJAR)
| ├ META-INF
| | └ ejb-jar.xml
| └ xxxxx
| ├ xxxxx.class
| └ xxxxx.class
└ xxxxx.war (WEBアプリ用のWAR)
└ WEB-INF
├ web.xml
└ classes
|
(2) ejb-jar.xml を作成する
<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>SampleBean</ejb-name>
<home>sample.SampleHome</home>
<remote>sample.Sample</remote>
<ejb-class>sample.SampleBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<session>
<ejb-name>StatefulBean</ejb-name>
<home>sample.StatefulHome</home>
<remote>sample.Stateful</remote>
<ejb-class>sample.StatefulBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
| ※ http://www.limy.org/program/j2ee/ejb-jar_2_0.html |
(3) application.xml を作成する
<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN'
'http://java.sun.com/dtd/application_1_3.dtd'>
<application>
<display-name>sapmleEAR</display-name>
<description>sapmleEAR</description>
<module>
<ejb>sampleejb.jar</ejb>
</module>
<module>
<web>
<web-uri>sampleweb.war</web-uri>
<context-root>sample</context-root>
</web>
</module>
</application>
|
(4) EAR作成用のAntスクリプトを作成する
<project name="myproject" default="make.ear" basedir="./">
<!-- WARファイル名 -->
<property name="war.name" value="sample.war"/>
<!-- EARファイル名 -->
<property name="ear.name" value="sample.ear"/>
<!-- EAR作成用の作業領域 -->
<property name="ear.tmp" value="build/tmp"/>
<!-- 展開EAR圧縮ファイル名 -->
<property name="ear.zip" value="sample.zip"/>
<!-- ソースディレクトリ -->
<property name="src.dir" value="path/to/WEB-INF/src" />
<!-- Classファイル出力先 -->
<property name="classes.dir" value="path/to//WEB-INF/classes" />
<!-- コンパイル実行 -->
<target name="build">
<javac listfiles="yes" srcdir="${src.dir}" destdir="${classes.dir}" encoding="Windows-31J">
<classpath>
<pathelement location="path/to/WEB-INF/lib/xxxxxxx.jar"/>
<pathelement location="path/to/WEB-INF/lib/xxxxxxx.jar"/>
<pathelement location="path/to/WEB-INF/lib/xxxxxxx.jar"/>
</classpath>
</javac>
</target>
<!-- WAR作成 -->
<target name="make.war" description="WAR作成" depends="build">
<delete file="${war.name}"/>
<war destfile="${war.name}" webxml="path/to/WEB-INF/web.xml">
<webinf dir="path/to/WEB-INF">
<exclude name="web.xml"/>
<exclude name="src/**"/>
</webinf>
<fileset dir="path/to/WebAppRoot">
<include name="etc/**"/>
<include name="html/**"/>
<include name="images/**"/>
<include name="jsp/**"/>
</fileset>
</war>
</target>
<!-- EAR作成 -->
<target name="make.ear" description="EAR作成" depends="make.war">
<delete dir="${ear.name}"/>
<delete dir="${ear.tmp}"/>
<mkdir dir="${ear.tmp}"/>
<mkdir dir="${ear.tmp}/${ear.name}"/>
<mkdir dir="${ear.tmp}/${ear.name}/${war.name}"/>
<mkdir dir="${ear.tmp}/${ear.name}/META-INF"/>
<copy todir="${ear.tmp}/${ear.name}/META-INF">
<fileset dir="build/META-INF">
<include name="**"/>
</fileset>
</copy>
<copy todir="${ear.tmp}/${ear.name}" file="${war.name}"/>
<ear appxml="build/META-INF/application.xml" destfile="${ear.name}">
<fileset dir="./">
<include name="${war.name}"/>
</fileset>
</ear>
</target>
<!-- 展開EAR作成 -->
<target name="make.openear" description="展開EAR作成">
<delete dir="${ear.name}"/>
<delete dir="${ear.tmp}"/>
<mkdir dir="${ear.tmp}"/>
<mkdir dir="${ear.tmp}/${ear.name}"/>
<mkdir dir="${ear.tmp}/${ear.name}/${war.name}"/>
<mkdir dir="${ear.tmp}/${ear.name}/META-INF"/>
<copy todir="${ear.tmp}/${ear.name}/META-INF">
<fileset dir="build/META-INF">
<include name="**"/>
</fileset>
</copy>
<copy todir="${ear.tmp}/${ear.name}/${war.name}">
<fileset dir="path/to/WebAppRoot">
<include name="**"/>
</fileset>
</copy>
<zip destfile="${ear.zip}" basedir="${ear.tmp}"/>
</target>
</project>
|