JBoss文档(二)——JBoss开发、打包、部署

<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> 1

第一章补充

我看了自己写第一章后,对于build.xml没有显示全面,现在补充如下:

<!-- Simple Ant build script to test an Ant installation
<project name="TestInstall" default="run" basedir=".">
<target name="init">
<available file="ASimpleHelloObject.java" property="ASimpleHelloObject"/>
</target>
<target name="ASimpleHelloObject" unless="ASimpleHelloObject" depends="init">
<echo file="ASimpleHelloObject.java">
public class ASimpleHelloObject
{
public static void main(String[] args)
{
System.out.println("ASimpleHelloObject.main was called");
}
}
</echo>
<echo message="Wrote ASimpleHelloObject.java" />
</target>
<target name="compile" depends="ASimpleHelloObject">
<javac destdir="." srcdir="." debug="on" classpath=".">
<include name="ASimpleHelloObject.java"/>
</javac>
</target>
<target name="run" depends="compile">
<java classname="ASimpleHelloObject" classpath="." />
<echo message="Ant appears to be successfully installed" />
</target>
</project>

1、下载例子源程序

所有例子的源代码,都在文件documentation-example.zip(windows平台) or documentation-example.tar.gz (Unix/Lunix平台)。你可以直接从 www.jboss.org进行下载。下载完后放在一个目录下。下载网址:http://www.jboss.org/docs/manual/files/documentation-example.zip

1.1 建立 BEAN
此节主要是建立一个简单的EJB,可以查看代码,这个“Interest”例子,是一个简单无状态的会话EJB。它的目的是根据说明的利息率,来对借的所有钱计算利息。实际上在整个包代码中只有一行功能。


1.2 回顾EJBs
在我们查看代码之前,我们先对EJB进行复习一下。在EJB最小类型,也必须有三个类:remote interface, home interface和bean实现类。
remote interface是会把EJB中方法提供给外边世界,让外边的代码来进行调用,在这个例子中类名称是org.jboss.interest.Interrest。
home interface是管理remote interface类的类。包括建立、删除等操作。在这个例子中类名称是org.jboss.interest.InterrestHome。
bean实现类提供home interface和remote interface所有方法的实现。在这个例子中类名称是org.jboss.interest.InterrestBean。


当然一个Bean可能还包括其他类,甚至其他包。但是必须有此三个类,其他类是在此三个类之上建立的。所有类被打包进一个JAR文件,此文件是用一个目录结构来反映出包的层次关系。在此例子中所有类都打包在org.jboss.interest包中,所以他们需要在目录org/jboss/interest/下。

在包含所有类的jar文件建立之前,必须有一个META-INF目录。此目录存放了部署描述符(通常叫“ejb-jar.xml”),和可选的其他XML文件。这些文件告诉服务器关于应用明确服务信息。对于JBoss 来讲,文件名必须叫“jboss.xml”。

创建jar文件后部署到JBoss Server上。在客户端你需要一个jndi.properties文件,此文件告诉你的客户端程序从哪里初始化查找JNDI 命名服务。从这个服务,客户端将查找到Interest bean,并且返回bean的home interface。home interface用来得到bean的一个remote interface。它可以用远程接口来访问bean提供的商业方法。

1.3 EJB类
我们需要三个类:remote interface, home interface 和bean实现类。remote interface远程接口类,文件名Interest.java。代码如下:

package org.jboss.docs.interest;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
This interface defines the `Remote' interface for the `Interest' EJB. Its
single method is the only method exposed to the outside world. The class
InterestBean implements the method.
*/
public interface Interest extends EJBObject
{
/** Calulates the compound interest on the sum `principle', with interest rate per period `rate' over `periods' time periods. This method also prints a message to standard output; this is picked up by the EJB server and logged. In this way we can demonstrate that the method is actually being executed on the server, rather than the client. */
public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException;
}

远程接口只有一个商业方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值