package com.customer.service;
import java.util.List;
import java.util.Properties;
import javax.naming.InitialContext;
import com.ejb.bean.TalkRemote;
import com.ejb.entity.Student;
public class findJNDI {
public static Object getTalkService(String jndiName) throws Exception
{
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:org.jnp.interfaces");
InitialContext ts = new InitialContext(props);
return ts.lookup(jndiName);
}
public static void main(String[] args) throws Exception {
TalkRemote t tr= null;
tr = (TalkRemote)findJNDI.getTalkService("Talk/remote");
List<Student> stu = tr.findStudentList();
}
}
如果以上代码运行报错,需要导入jbossall-client.jar包,该包位于client文件夹下。
推荐使用Junit4测试,这样效益更高。