假设我已经把EJB做好了,是一个HelloWorld,下面说如何发布 Bean文件如下:
package han.ejb;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
/**
* XDoclet-based session bean. The class must be declared
* public according to the EJB specification.
*
* To generate the EJB related files to this EJB:
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration for your appserver
* - Run XDoclet
* Below are the xdoclet-related tags needed for this EJB.
* @ejb.bean name="HelloWorldBean"
* display-name="HelloWorld"
* description="Description for HelloWorld"
* jndi-name="ejb/HelloWorld"
* remote="HelloWorldRemote"
* type="Stateless"
* view-type="remote"
*/
public class HelloWorldBean implements SessionBean {
private static final long serialVersionUID = 1L;
public HelloWorldBean() {
// TODO Auto-generated constructor stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/**
* Set the associated session context. The container calls this method
* after the instance creation.
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable.
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setSessionContext(SessionContext newContext)
throws EJBException {
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s <code>ejbCreate</code> method whose
* signature matches the signature of the <code>create</code> method invoked
* by the client. The input parameters sent from the client are passed to
* the <code>ejbCreate</code> method. Each session bean class must have at
* least one <code>ejbCreate</code> method. The number and signatures
* of a session bean?s <code>create</code> methods are specific to each
* session bean class.
*
* @throws CreateException Thrown if method fails due to system-level error.
*
* @ejb.create-method
*
*/
public void ejbCreate() throws CreateException {
// TODO Add ejbCreate method implementation
}
/**
* An example business method
*
* @ejb.interface-method view-type = "remote"
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
@RemoteMethod()
@WebMethod()
public String sayhello() throws EJBException {
// rename and start putting your business logic here
return new String("Hello EJB!");
}
}
事实上JSR 181是BEA提出的用于加速Web Services开发的一种基于注释驱动的编程模式,并被批准纳入到J2EE 1.5标准。JSR181提供了一种简单的Web Service开发编程模型和标准的编译及部署方式。只需要编写JSR-175风格的注释就可以制定WSDL,消息产生属性,安全认证方式,以及特定的消息头。
1.所以,如果要把SESSION BEAN发布为WEB服务,必须在JDK 1.5下做,安装MyEclipse的话,JDK会自动被升级到1.6,所以要先改回来。
Project->properties->java build path,选中JDK,EDIT

从Alternate JRE中选JDK 1.5,注意,如果是自己的JDK,版本一定不能高过BEA带的JDK
2.添加注释
@JndiName(remote="han.interfaces.HelloWorldBean")
@WebService(name="HelloWorldPortType", //端口名
serviceName="HelloWorldService", //服务名
targetNamespace="http://ejb.han") //WebService注释是必须有的,下面的WLHttpTransport和SOAPBinding是推荐的
@WLHttpTransport(contextPath="Hello_EJB",
serviceUri="HelloWorldService", //http://localhost:7001/contextPath/services/serviceUri?wsdl
portName="HelloWorldPort")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, //好象都这么写
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
添加业务逻辑注释
@RemoteMethod()
@WebMethod()
导入相关包
import weblogic.jws.WLHttpTransport;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import weblogic.ejbgen.JndiName;
import weblogic.ejbgen.RemoteMethod;
import weblogic.jws.WLHttpTransport;


3.创建build.xml文件(注释是后写的,所以不符合规范)
<projectname="webservice-HelloWorld"default="all"> //工程(默认的任务是all)
<propertyname="example-output"value="output"/>
<propertyname="ear-dir"value="${example-output}"/>
<propertyname="src-dir"value="./src"/>
<taskdefname="jwsc"classname="weblogic.wsee.tools.anttasks.JwscTask"/> //Ant任务
<targetname="all"depends="clean,build-service"/> //target:all
<targetname="clean"> //target:clean
<deletedir="${example-output}"/> //文件目录
</target>
<targetname="build-service"depends=" //target:build-service
<jwscsrcdir="${src-dir}"destdir="${ear-dir}"> //源目录和目标目录
<module> //添加jws文件(可以多个)
<jwsfile="han/ejb/HelloWorldBean.java"/> /jws文件(包含注释的文件)
</module>
</jwsc>
</target>
</project>
4.Run Ant

会发现生成了两个文件(application.xml和weblogic-application.xml)和一个JAR(jws.jar)包
5.部署
启动服务器,进入console,手动部署

处于ACTIVE状态

然后写个客户断就可以测试了