Topic: 哦初学ejb遇到的问题

  Print this page

1.哦初学ejb遇到的问题 Copy to clipboard
Posted by: zhb
Posted on: 2006-08-01 15:47

哦刚刚开始看ejb 遇到问题
看 精通EJB 第3版 第一个例子 helloword
在Jboos中部署好了 剩下客户端 的 HelloClient.java 编译后 不知道该放哪 或者怎样让它正常运行 得到输出的语句....

2.Re:哦初学ejb遇到的问题 [Re: zhb] Copy to clipboard
Posted by: why
Posted on: 2006-08-03 08:59

http://www.cjsdn.net/post/view?bid=2&id=179194

jboss中 部署好了

Clinet

package examples;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;

/**
* This class is an example of client code which invokes
* methods on a simple stateless session bean.
*/
public class HelloClient {

public static void main(String[] args) throws Exception {
/*
* Setup properties for JNDI initialization.
*
* These properties will be read-in from
* the command-line.
*/
Properties props = System.getProperties();

/*
* Obtain the JNDI initial context.
*
* The initial context is a starting point for
* connecting to a JNDI tree. We choose our JNDI
* driver, the network location of the server, etc
* by passing in the environment properties.
*/
Context ctx = new InitialContext(props);

/*
* Get a reference to the home object - the
* factory for Hello EJB Objects
*/
Object obj = ctx.lookup("HelloHome");

/*
* Home objects are RMI-IIOP objects, and so
* they must be cast into RMI-IIOP objects
* using a special RMI-IIOP cast.
*
* See Appendix X for more details on this.
*/
HelloHome home = (HelloHome)
javax.rmi.PortableRemoteObject.narrow(
obj, HelloHome.class);

/*
* Use the factory to create the Hello EJB Object
*/
Hello hello = home.create();

/*
* Call the hello() method on the EJB object. The
* EJB object will delegate the call to the bean,
* receive the result, and return it to us.
*
* We then print the result to the screen.
*/
System.out.println(hello.hello());

/*
* Done with EJB Object, so remove it.
* The container will destroy the EJB object.
*/
hello.remove();
}
}

编译然后java Hello

错误
Exception in thread "main" javax.naming.NoInitialContextException: Need to speci
fy class name in environment or system property, or as an applet parameter, or i
n an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
45)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247
)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at examples.HelloClient.main(HelloClient.java:36)
Press any key to continue...
这个到底该怎么运行阿 mastering ejb上 也没有说


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923