为何有此异常?(50分)

  • 主题发起人 主题发起人 chenlh
  • 开始时间 开始时间
C

chenlh

Unregistered / Unconfirmed
GUEST, unregistred user!
C:/>java ejb.client
1
Caught an unexpected exception!
javax.naming.CommunicationException: Can't find SerialContextProvider
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
a:60)
at com.sun.enterprise.naming.SerialContext.<init>(SerialContext.java:79)
at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext(
SerialInitContextFactory.java:54)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
68)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:178)
at ejb.client.main(client.java:23)
 
源代码
package ejb;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import ejb.Demo;
import ejb.DemoHome;
public class client {
public static void main(String[] args) {
try {
System.out.println("1");
Context initial = new InitialContext();
System.out.println("2");
Object objref = initial.lookup("HomeJNDIDemo");
System.out.println("3");

DemoHome home =
(DemoHome)PortableRemoteObject.narrow(objref,
DemoHome.class);
System.out.println("4");
Demo hs = home.create();
System.out.println(hs.demoSelect());
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}

}
问题出在Context initial = new InitialContext();,为什么?
home,remote接口和session bean已经做好。
 
在生成上下文时需要提供环境参数的,仔细看文档吧。
 
接受答案了.
 
后退
顶部