当前位置: 技术问答>java相关
为什麽JNDI找不到EJBHome接口??
来源: 互联网 发布时间:2015-08-15
本文导语: 我做了一个j2ee的小工程,有TraderHome,Trader两个接口,有TradeResult,TraderBean两个类,还有一个client 用于测试客户端,所有文件都编译成功后,在命令提示符下打t3://localhost:7001,可是总出现一个错误,在命 令行窗口下提示...
我做了一个j2ee的小工程,有TraderHome,Trader两个接口,有TradeResult,TraderBean两个类,还有一个client
用于测试客户端,所有文件都编译成功后,在命令提示符下打t3://localhost:7001,可是总出现一个错误,在命
令行窗口下提示为:"The client was unable to lookup the EjBHome,please make sure that you have deployed
the ejb with the JNDI name statelessSession.TradeHome on the Weblogic server at t3://localhost:7001."
就是说接口JNDI找不到EJBHome接口,可我已经把它们都对应起来了,在xml文件里也是对应的,它为什麽找不到?
请用过j2ee的高手指点一下吧!多谢!以下是我的TraderHome.java和Client.java文件:///////////////////////TraderHome.java/////////////////////
package examples.ejb.basic.statelessSession;
//javax.ejb.EJBHome定义了EJB主接口,被用户定义的主接口继承
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface TraderHome extends EJBHome {
Trader create() throws CreateException, RemoteException;
}
///////////////////Client.java////////////////////////////////
//定义本类在包examples.ejb.basic.statelessSession中
package examples.ejb.basic.statelessSession;
//本类用到的其他类
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;
import javax.rmi.PortableRemoteObject;
/**
* 这个类演示了如何调用一个会话,并进行如下操作:
* 创建一个Trader远程对象
* 使用Trader远程对象购买一定数量的股票
* 出售一定数量的股票
* 清除Trader远程对象
*/
public class Client {
//定义JNDI服务中EJB的名称
private static final String JNDI_NAME = "statelessSession.TraderHome";
//声明应用服务器的URL变量
private String url;
//声明主接口变量
private TraderHome home;
public Client(String url)
throws NamingException
{
this.url = url;
//寻找主接口
home = lookupHome();
}
/**
* 在命令行运行这个实例:
* java examples.ejb.basic.statefulSession.Client "t3://localhost:7001"
* 参数是可选的
*/
public static void main(String[] args) throws Exception {
log("nBeginning statelessSession.Client...n");
//声明应用服务器地址变量
String url = "t3://localhost:7001";
// Parse the argument list
if (args.length != 1) {
//打印用法提示
System.out.println("Usage: java examples.ejb.basic.statelessSession.Client t3://hostname:port");
return;
} else {
url = args[0];
}
Client client = null;
try {
//创建客户端实例
client = new Client(url);
} catch (NamingException ne) {
System.exit(1);
}
try {
//调用测试方法
client.example();
} catch (Exception e) {
//异常处理
log("There was an exception while creating and using the Trader.");
log("This indicates that there was a problem communicating with the server: "+e);
}
log("nEnd statelessSession.Client...n");
}
/**
* 运行实例
*/
public void example()
throws CreateException, RemoteException, RemoveException
{
// 创建远程对象
log("Creating a trader");
Trader trader = (Trader) narrow(home.create(), Trader.class);
String [] stocks = {"BEAS", "MSFT", "AMZN", "HWP" };
// 执行一系列购买操作
for (int i=0; i
用于测试客户端,所有文件都编译成功后,在命令提示符下打t3://localhost:7001,可是总出现一个错误,在命
令行窗口下提示为:"The client was unable to lookup the EjBHome,please make sure that you have deployed
the ejb with the JNDI name statelessSession.TradeHome on the Weblogic server at t3://localhost:7001."
就是说接口JNDI找不到EJBHome接口,可我已经把它们都对应起来了,在xml文件里也是对应的,它为什麽找不到?
请用过j2ee的高手指点一下吧!多谢!以下是我的TraderHome.java和Client.java文件:///////////////////////TraderHome.java/////////////////////
package examples.ejb.basic.statelessSession;
//javax.ejb.EJBHome定义了EJB主接口,被用户定义的主接口继承
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface TraderHome extends EJBHome {
Trader create() throws CreateException, RemoteException;
}
///////////////////Client.java////////////////////////////////
//定义本类在包examples.ejb.basic.statelessSession中
package examples.ejb.basic.statelessSession;
//本类用到的其他类
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;
import javax.rmi.PortableRemoteObject;
/**
* 这个类演示了如何调用一个会话,并进行如下操作:
* 创建一个Trader远程对象
* 使用Trader远程对象购买一定数量的股票
* 出售一定数量的股票
* 清除Trader远程对象
*/
public class Client {
//定义JNDI服务中EJB的名称
private static final String JNDI_NAME = "statelessSession.TraderHome";
//声明应用服务器的URL变量
private String url;
//声明主接口变量
private TraderHome home;
public Client(String url)
throws NamingException
{
this.url = url;
//寻找主接口
home = lookupHome();
}
/**
* 在命令行运行这个实例:
* java examples.ejb.basic.statefulSession.Client "t3://localhost:7001"
* 参数是可选的
*/
public static void main(String[] args) throws Exception {
log("nBeginning statelessSession.Client...n");
//声明应用服务器地址变量
String url = "t3://localhost:7001";
// Parse the argument list
if (args.length != 1) {
//打印用法提示
System.out.println("Usage: java examples.ejb.basic.statelessSession.Client t3://hostname:port");
return;
} else {
url = args[0];
}
Client client = null;
try {
//创建客户端实例
client = new Client(url);
} catch (NamingException ne) {
System.exit(1);
}
try {
//调用测试方法
client.example();
} catch (Exception e) {
//异常处理
log("There was an exception while creating and using the Trader.");
log("This indicates that there was a problem communicating with the server: "+e);
}
log("nEnd statelessSession.Client...n");
}
/**
* 运行实例
*/
public void example()
throws CreateException, RemoteException, RemoveException
{
// 创建远程对象
log("Creating a trader");
Trader trader = (Trader) narrow(home.create(), Trader.class);
String [] stocks = {"BEAS", "MSFT", "AMZN", "HWP" };
// 执行一系列购买操作
for (int i=0; i