5.3. Hibernate MBean Service DescriptorNow that we have the HBM file in place, we must create an MBean service configuration file for Hibernate. Hibernate is a service, no different than Hypersonic or any of the others. Each MBean needs a service configuration file like Example 5-4 so that JBoss will recognize it and run it on startup. Example 5-4. hibernate-service.xml
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/JBossAtWorkDS</attribute>
<attribute name="Dialect"> org.hibernate.dialect.HSQLDialect</attribute>
<attribute name="SessionFactoryName">
java:/hibernate/SessionFactory</attribute>
<attribute name="CacheProviderClass">
org.hibernate.cache.HashtableCacheProvider
</attribute>
</mbean>
</server>
Let's step through it line by line.
|
5.4. Creating a HARNow that we created the HBM files and the Hibernate MBean service deployment descriptor, we are ready to bundle things up and deploy it as a part of the EAR. Hibernate applications are bundled up in a Hibernate Archive (HAR). We use the standard Ant <jar> task in Example 5-5 to create the HAR. Example 5-5. build.xml
<!-- ====================================== -->
<target name="har" depends="generate-hbm"
description="Builds the Hibernate HAR file">
<mkdir dir="${distribution.dir}" />
<jar destfile="${distribution.dir}/jaw.har">
<!-- include the hbm.xml files -->
<fileset dir="${gen.source.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
<!-- include hibernate-service.xml -->
<metainf dir="${hibernate.dir}">
<include name="hibernate-service.xml"/>
</metainf>
</jar>
</target>
|
5.5. Adding the HAR to the EARMoving up a level from the common subproject to the master project, we need to make sure that the EAR file includes our newly created HAR. The master build file already handles this step, since the jaw.har file is built in the same directory as common.jar . (Look in common/build/distribution to confirm this.) But what about our application.xml file? This is traditionally where we identify the JARs that are included in the EAR. HARs are not a standard part of a J2EE EAR file, so JBoss looks for a jboss-app.xml file to handle container-specific exceptions to the standard. src/META-INF/ stores this file, right next to your application.xml file. Example 5-6 shows what it looks like. Example 5-6. jboss-app.xml
<!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
<module>
<har>jaw.har</har>
</module>
</jboss-app>
Our <ear> task now includes this file along with the traditional application.xml in Example 5-7. Example 5-7. Master build.xml
<!-- ====================================== -->
<target name="ear" depends="compile"
description="Packages all files into an EAR file">
<mkdir dir="${build.dir}" />
<mkdir dir="${distribution.dir}" />
<echo message="##### Building EAR #####" />
<ear destFile="${distribution.dir}/${ear.name}"
appxml="${meta-inf.dir}/application.xml" >
<!-- files to be included in / -->
<fileset dir="${webapp.war.dir}" />
<fileset dir="${common.jar.dir}" />
<!-- include jboss-app.xml -->
<metainf dir="${meta-inf.dir}">
<include name="jboss-app.xml"/>
</metainf>
</ear>
</target>
|
![]() JBoss: A Developer's Notebook | ![]() Java Message Service | ![]() JBoss AS 7 Configuration, Deployment and Administration | ![]() JBoss in Action: Configuring the JBoss Application Server |
![]() JBoss: A Developer's Notebook | ![]() Java Message Service |
![]() JBoss AS 7 Configuration, Deployment and Administration | ![]() JBoss in Action: Configuring the JBoss Application Server |