【发布时间】:2011-10-23 21:58:39
【问题描述】:
我创建了一个从我的应用程序客户端启动的小型 junit 测试。 我的服务器是 glassfish 3.1.1 。 当我运行测试时,我得到了这个错误:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
我已经将属性添加到上下文中,但没有任何改变。 这就是我设置上下文的方式:
@Before
public void setUp() throws NamingException {
Properties props = new Properties();
System.out.println("launch");
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
//props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
//props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
Context annuaire = new InitialContext(props);
GeoBeanRemote service = (GeoBeanRemote) annuaire.lookup(GeoBeanRemote.class.getName());
BeanProvider.setGeoBean(service);
}
app-serv.rt 和 gf-client 已添加到我的运行测试中。
谢谢。
【问题讨论】:
-
如果您使用的是 GlassFish v3+,您的类路径中应该只需要 gf-client.jar
-
你能显示异常堆栈跟踪吗?
标签: java jakarta-ee junit glassfish ejb-3.0