import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Collection;
import java.util.Iterator;
import java.util.Enumeration;public class Test{
MsSqlJbossRemote msSqlJbossRemote;
MsSqlJbossRemoteHome msSqlJbossRemoteHome;
public Test(){
InitialContext jndi = new InitialContext();
Object obj = Object ref = ctx.lookup("MsSqlJbossRemote");
msSqlJbossRemoteHome = (MsSqlJbossRemoteHome)
PortableRemoteObject.narrow(ref, MsSqlJbossRemoteHome.class);
}
}
import javax.rmi.PortableRemoteObject;
import java.util.Collection;
import java.util.Iterator;
import java.util.Enumeration;public class Test{
MsSqlJbossRemote msSqlJbossRemote;
MsSqlJbossRemoteHome msSqlJbossRemoteHome;
public Test(){
InitialContext jndi = new InitialContext();
Object obj = Object ref = ctx.lookup("MsSqlJbossRemote");
msSqlJbossRemoteHome = (MsSqlJbossRemoteHome)
PortableRemoteObject.narrow(ref, MsSqlJbossRemoteHome.class);
}
}
解决方案 »
- 关于空格显示的问题
- struts Hibernate Spring结合问题
- 关于正则表达式pattern类的matcher匹配的问题..
- spring+hibernate+struts+eclipse的分布问题
- 求助?????
- 简单问题求助
- 要多少分就能给多少,谁了解FLEX的J2EE解决方案???
- apache axis 如何序列化一个参数,比如序列化FILE等,在部署文件里和客户端程序怎么完成。求救啊!!!!!
- java串口通讯
- 急::那位大哥有用java写的将oracle数据库里的表导成文本文件实例??(在线等,给分)
- to:luckweb(冰川) 请进
- (50)请教一个关于XML的问题?
MsSqlJbossRemoteHome msSqlJbossRemoteHome=null;
package clientprj;
import javax.naming.*;
import javax.ejb.*;
import java.util.Properties;
public class client {
public static void main(String[] args) {
HelloBean1 hb1=null;
HelloBean1Home hb1home=null;
client c1=new client();
try{
Properties props=System.getProperties();
/*Context ctx=new InitialContext(props);*/
Context ctx=c1.getInitialContext();
hb1home=(HelloBean1Home)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("HelloBean1"),HelloBean1LocalHome.class);
hb1=hb1home.create();
hb1.Sayhello();
hb1.remove();
}
catch(Exception e){
e.printStackTrace();
}
}
private Context getInitialContext() throws Exception {
String url = "t3://piccl:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) { throw e;
}
}
}
但是执行中产生如下错误:
java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296) at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137) at clientprj.client.main(client.java:16)请问,如何解决啊?谢谢各位了
你看看是不是同时import了两个相同的类
改为hb1home=(HelloBean1Home)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("HelloBean1"),HelloBean1Home.class);
转型错误