|
这个主题共有 3 回复 / 1 页 [
]
|
|
|
|
|
|
求助:HELLOWORLD EJB入门部署 折腾了3天了,吐血啊.
|
发表: 2007年06月22日 10:49
|
回复
|
|
小弟不才,最近在研究EJB.开头的例子HELLOWORLD..看了网上无数例子,总是无法跑通,很多例子本有就有问题.经过3天,终于部署成功,但是无法运行,JNDI出错,实在没有办法了,网上找不到资料,请高手指点下迷途的羔羊. 第一个类:package examples; import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface Hello extends EJBObject { public String hello() throws RemoteException; } 第二个类 package examples; import javax.ejb.SessionContext; public class HelloBean implements javax.ejb.SessionBean { private SessionContext ctx; public void EJBCreate() { System.out.print("ejbCreate()"); } public void EJBRemove() { System.out.print("ejbRemove()"); } public void EJBActivate() { System.out.print("ejbActivate()"); }
public void EJBPassivate() { System.out.print("ejbPassivate"); } public void setSessionContext(javax.ejb.SessionContext ctx) { this.ctx = ctx; } public String hello() { System.out.print("hello()"); return "Hello World~!"; } } 第三个类:package examples; public interface HelloHome extends javax.ejb.EJBHome{ Hello create()throws java.rmi.RemoteException,javax.ejb.CreateException; } XML: <?xml version="1.0" encoding="UTF-8"?> <!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>Hello</ejb-name> <Home>examples.HelloHome</Home> <Remote>examples.Hello</Remote> <ejb-class>examples.HelloBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> </Session> </enterprise-beans> </ejb-jar>
打包成HelloWorld.jar 放在JBOSS Deploy 文件夹下...然后运行测试文件:
package examples;
import java.rmi.RemoteException; import java.util.Properties;
import javax.ejb.CreateException; import javax.ejb.RemoveException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException;
public class test { public static void main(String args[]) throws NamingException, RemoteException, CreateException, RemoveException {
Properties props = new Properties(); props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); props.setProperty("java.naming.provider.url","localhost:1099"); props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome Home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class); Hello hello = Home.create();
System.out.print(hello.hello()); hello.remove(); } }
部署成功了,但是测试一直出错 Exception in thread "main" javax.naming.NameNotFoundException: HelloHome not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
实在是不行了,请坛子的高手们抽几分钟看下....已经痛苦3天了.
|
|
|
|
|
|
re:求助:HELLOWORLD EJB入门部署 折腾了3天了,吐血啊.
|
发表: 2007年06月22日 18:43
|
回复
|
|
|
写什么写,找个好的IDE。自动生成,你只要在你需要的地方写代码就行了。
|
|
|
|
|
|
re:求助:HELLOWORLD EJB入门部署 折腾了3天了,吐血啊.
|
发表: 2007年06月23日 15:47
|
回复
|
|
代码看得头晕呀,有那么多代码吗? 就只是输出一个HELLO WORD? 小题大做。你用ECLIPSE,试试,这个工具我经常用,还好。
|
|
|
|
|
|
re:求助:HELLOWORLD EJB入门部署 折腾了3天了,吐血啊.
|
发表: 2007年06月23日 18:24
|
回复
|
|
默认jndi是<ejb-name>Hello</ejb-name>
Object obj = ctx.lookup("Hello");
|
|
|
|