java.lang.ClassCastException com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow

1 篇文章 0 订阅

一直在ide中调试 ejb,今天有个东西想不明白,懒的开ide,就用编辑器自己写,发现真吃力啊,import 就写不明白了,后来算啦,清一色的都 import javax.ejb.*;import java.util.*; import javax.persistence.*; 发现没有ide,自己还能干点什么,估计每天都在看java-doc了.....

终于写完ejb了,编译过了,都没用ant,直接javac的....  没有F3,只用split真是太不爽啊,编译后,拷贝到jboss/server/default/deploy后,使用client,却始终跑不起来,在PortableRemoteObject.narrow时一个劲的 出现ClassCastException,

Exception in thread "main" java.lang.ClassCastException
>-------at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
>-------at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
>-------at com.ss.clients.Client1.main(Client1.java:18)
Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be cast to org.omg.CORBA.Object
>-------at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
>-------... 2 more

 

使用nohup java -cp .:jnp-client.jar:jbossws-spi.jar:ss.jar:jboss-logging-spi.jar com/ss/clients/Client1 郁闷,代码类似于:

 

-------public static void main(String[] args) throws Exception {
>------->-------Context jndiContext = getInitialContext();
>------->-------out(jndiContext);
>------->-------Object ref = jndiContext.lookup("SSBean/remote");
>------->-------out(ref);
>------->-------SSRemote remote = (SSRemote)
>------->-------  PortableRemoteObject.narrow(ref, SSRemote.class);
>-------}

>-------public static Context getInitialContext() throws javax.naming.NamingException {
>------->-------Properties p = new Properties();
>------->-------p.put(Context.INITIAL_CONTEXT_FACTORY,
>------->------->-------"org.jnp.interfaces.NamingContextFactory");
>------->-------p.put(Context.URL_PKG_PREFIXES,
>------->------->-------"org.jboss.naming:org.jnp.interfaces");
>------->-------p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
>------->-------return new InitialContext(p);
>-------}
>-------private static void out(Object o ) {
>------->-------System.out.println(o);
>------->-------System.out.println(o.getClass());
>------->-------System.out.println("--------------------");
>-------}

 

faint,几经周折,还是被迫打开eclipse,看了看

Object com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Object narrowFrom, Class narrowTo) throws ClassCastException

if (narrowTo.isInterface() &&
        narrowTo != java.io.Serializable.class &&
        narrowTo != java.io.Externalizable.class) {
  
        org.omg.CORBA.Object narrowObj
            = (org.omg.CORBA.Object) narrowFrom;              
      
        // Create an id from the narrowTo type...
        String id = RepositoryId.createForAnyType(narrowTo);
      
        if (narrowObj._is_a(id)) {
            return Utility.loadStub(narrowObj,narrowTo);
        } else {
            throw new ClassCastException( "Object is not of remote type " +
            narrowTo.getName() ) ;
        }
        } else {
        throw new ClassCastException( "Class " + narrowTo.getName() +
            " is not a valid remote interface" ) ;
 }

 

没什么毛病啊....   shit,再看看

Object javax.rmi.PortableRemoteObject.narrow(Object narrowFrom, Class narrowTo) throws ClassCastException

 

    public static java.lang.Object narrow ( java.lang.Object narrowFrom,
                                            java.lang.Class narrowTo)
    throws ClassCastException {

    if (proDelegate != null) {
        return proDelegate.narrow(narrowFrom, narrowTo);
    }
    return null;
          
    }

 

也没什么,== 这个 delegator是什么,终于可以 f3了,

    private static javax.rmi.CORBA.PortableRemoteObjectDelegate proDelegate = null;

    private static final String PortableRemoteObjectClassKey =
            "javax.rmi.CORBA.PortableRemoteObjectClass";

    private static final String defaultPortableRemoteObjectImplName =
            "com.sun.corba.se.impl.javax.rmi.PortableRemoteObject";

    static {
        proDelegate = (javax.rmi.CORBA.PortableRemoteObjectDelegate)
            createDelegateIfSpecified(PortableRemoteObjectClassKey);
    }

 


    private static Object createDelegateIfSpecified(String classKey) {
        String className = (String)
            AccessController.doPrivileged(new GetPropertyAction(classKey));
        if (className == null) {
            Properties props = getORBPropertiesFile();
            if (props != null) {
                className = props.getProperty(classKey);
            }
        }
    if (className == null) {
        className = defaultPortableRemoteObjectImplName;
    }

        try {
            return (Object) loadDelegateClass(className).newInstance();
        } catch (ClassNotFoundException ex) {
        INITIALIZE exc = new INITIALIZE( "Cannot instantiate " + className);
        exc.initCause( ex ) ;
        throw exc ;
        } catch (Exception ex) {
        INITIALIZE exc = new INITIALIZE( "Error while instantiating" + className);
        exc.initCause( ex ) ;
        throw exc ;
        }

    }

 

看明白了,nnd,原来delegator是从System.getProperties()里面取的,难道缺jarball?去 $JBOSS_HOME/client里面考,全拷贝过来,都加到cp里去,类似于

 

java -cp /home/jactive/test/mm/activation.jar:/home/jactive/test/mm/antlr.jar:/home/jactive/test/mm/avalon-framework.jar:/home/jactive/test/mm/commons-logging.jar:/home/jactive/test/mm/concurrent.jar:/home/jactive/test/mm/ejb3-persistence.jar:/home/jactive/test/mm/FastInfoset.jar:/home/jactive/test/mm/getopt.jar:/home/jactive/test/mm/hibernate-annotations.jar:/home/jactive/test/mm/jacorb.jar:/home/jactive/test/mm/javassist.jar:/home/jactive/test/mm/jaxb-api.jar:/home/jactive/test/mm/jaxb-impl.jar:/home/jactive/test/mm/jaxb-xjc.jar:/home/jactive/test/mm/jaxws-rt.jar:/home/jactive/test/mm/jaxws-tools.jar:/home/jactive/test/mm/jbossall-client.jar:/home/jactive/test/mm/jboss-aop-client.jar:/home/jactive/test/mm/jboss-appclient.jar:/home/jactive/test/mm/jboss-aspect-jdk50-client.jar:/home/jactive/test/mm/jboss-client.jar:/home/jactive/test/mm/jboss-common-core.jar:/home/jactive/test/mm/jbosscx-client.jar:/home/jactive/test/mm/jboss-deployers-client.jar:/home/jactive/test/mm/jboss-deployers-client-spi.jar:/home/jactive/test/mm/jboss-deployers-core.jar:/home/jactive/test/mm/jboss-deployers-core-spi.jar:/home/jactive/test/mm/jboss-deployers-vfs.jar:/home/jactive/test/mm/jboss-deployers-vfs-spi.jar:/home/jactive/test/mm/jboss-deployment.jar:/home/jactive/test/mm/jboss-ejb3-common-client.jar:/home/jactive/test/mm/jboss-ejb3-core-client.jar:/home/jactive/test/mm/jboss-ejb3-ext-api-impl.jar:/home/jactive/test/mm/jboss-ejb3-ext-api.jar:/home/jactive/test/mm/jboss-ejb3-proxy-clustered-client.jar:/home/jactive/test/mm/jboss-ejb3-proxy-impl-client.jar:/home/jactive/test/mm/jboss-ejb3-proxy-spi-client.jar:/home/jactive/test/mm/jboss-ejb3-security-client.jar:/home/jactive/test/mm/jboss-ha-client.jar:/home/jactive/test/mm/jboss-ha-legacy-client.jar:/home/jactive/test/mm/jboss-iiop-client.jar:/home/jactive/test/mm/jboss-integration.jar:/home/jactive/test/mm/jboss-j2se.jar:/home/jactive/test/mm/jboss-jaspi-api.jar:/home/jactive/test/mm/jboss-javaee.jar:/home/jactive/test/mm/jbossjmx-ant.jar:/home/jactive/test/mm/jboss-jsr77-client.jar:/home/jactive/test/mm/jbossjts-integration.jar:/home/jactive/test/mm/jbossjts.jar:/home/jactive/test/mm/jboss-logging-jdk.jar:/home/jactive/test/mm/jboss-logging-log4j.jar:/home/jactive/test/mm/jboss-logging-spi.jar:/home/jactive/test/mm/jboss-main-client.jar:/home/jactive/test/mm/jboss-mdr.jar:/home/jactive/test/mm/jboss-messaging-client.jar:/home/jactive/test/mm/jboss-metadata.jar:/home/jactive/test/mm/jboss-remoting.jar:/home/jactive/test/mm/jboss-security-spi.jar:/home/jactive/test/mm/jboss-serialization.jar:/home/jactive/test/mm/jboss-srp-client.jar:/home/jactive/test/mm/jbosssx-as-client.jar:/home/jactive/test/mm/jbosssx-client.jar:/home/jactive/test/mm/jboss-system-client.jar:/home/jactive/test/mm/jboss-system-jmx-client.jar:/home/jactive/test/mm/jbossws-common.jar:/home/jactive/test/mm/jbossws-framework.jar:/home/jactive/test/mm/jbossws-jboss50.jar:/home/jactive/test/mm/jbossws-native-client.jar:/home/jactive/test/mm/jbossws-native-core.jar:/home/jactive/test/mm/jbossws-native-jaxrpc.jar:/home/jactive/test/mm/jbossws-native-jaxws-ext.jar:/home/jactive/test/mm/jbossws-native-jaxws.jar:/home/jactive/test/mm/jbossws-native-saaj.jar:/home/jactive/test/mm/jbossws-spi.jar:/home/jactive/test/mm/jboss-xml-binding.jar:/home/jactive/test/mm/jettison.jar:/home/jactive/test/mm/jmx-client.jar:/home/jactive/test/mm/jmx-invoker-adaptor-client.jar:/home/jactive/test/mm/jnp-client.jar:/home/jactive/test/mm/log4j.jar:/home/jactive/test/mm/logkit.jar:/home/jactive/test/mm/mail.jar:/home/jactive/test/mm/out:/home/jactive/test/mm/policy.jar:/home/jactive/test/mm/scout.jar:/home/jactive/test/mm/slf4j-api.jar:/home/jactive/test/mm/slf4j-jboss-logging.jar:/home/jactive/test/mm/stax-api.jar:/home/jactive/test/mm/stax-ex.jar:/home/jactive/test/mm/streambuffer.jar:/home/jactive/test/mm/trove.jar:/home/jactive/test/mm/wsdl4j.jar:/home/jactive/test/mm/wstx.jar:/home/jactive/test/mm/xmlsec.jar:ss.jar:. com/ss/clients/Client1

 

够长的哈,运行通过了,终于消停了,后来改了改cp,缩小为


java -cp /home/jactive/test/mm/jboss-aop-client.jar:/home/jactive/test/mm/jboss-aspect-jdk50-client.jar:/home/jactive/test/mm/jboss-ejb3-common-client.jar:/home/jactive/test/mm/jboss-ejb3-core-client.jar:/home/jactive/test/mm/jboss-ejb3-ext-api-impl.jar:/home/jactive/test/mm/jboss-ejb3-ext-api.jar:/home/jactive/test/mm/jboss-ejb3-proxy-clustered-client.jar:/home/jactive/test/mm/jboss-ejb3-proxy-impl-client.jar:/home/jactive/test/mm/jboss-ejb3-proxy-spi-client.jar:/home/jactive/test/mm/jboss-ejb3-security-client.jar:/home/jactive/test/mm/jboss-logging-spi.jar:/home/jactive/test/mm/jboss-messaging-client.jar:/home/jactive/test/mm/jboss-remoting.jar:/home/jactive/test/mm/jettison.jar:/home/jactive/test/mm/jmx-client.jar:/home/jactive/test/mm/jmx-invoker-adaptor-client.jar:/home/jactive/test/mm/jnp-client.jar:/home/jactive/test/mm/log4j.jar:/home/jactive/test/mm/logkit.jar:/home/jactive/test/mm/mail.jar:ss.jar:. com/ss/clients/Client1

 

靠,这不就eclipse里面的Library吗,至此弄清楚一件事:永远不要拒绝工具,尤其在开发ejb这样麻烦的东西时

 

还有就是看看吧,自己的ss.jar完全被中间件jarball给吞没了
~                                                                                                                          
~

 

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值