这一段代码应该没有问题,但是ejb开发测试过程中可以出问题的地方太多了。
首先,你看看该SessionBean部署的时候jboss后台有没有报错,即一些exception和error。如果没有的话基本上可以肯定是client端的问题(针对上面的代码而言,因为只要部署没有问题是肯定可以得到远程接口的)
然后,有好几种方法可以查看jndi的绑定情况:1)察看jboss的jmx-console服务http://localhost:8080/jmx-console/index.jsp
2)eclipse有自带的jndi explorer可以查看所有的jndi绑定情况
3)这里当然还可以进程序调试看一看啦。先看一下有没有正常得到Context,如果有的话那就是你的jboss问题,可能没有正常启动,可能就是端口等设置不是正常情况;如果Context没有问题,ejb部署也没有问题,那么就肯定是jndi有问题了,那就仔细检查一下吧
最后,ejb是很搞,有的时候很简单的问题搞半天也不知道什么原因,最要细心拉!祝你好运!!

解决方案 »

  1.   

    这个问题通常是没有把client端的jar文件放到classpath中导致的。
    解决方法,放到classpath中,一切OK
      

  2.   

    雨兄分析得很对,(jmx-console中)Global JNDI Namespace的根下的确没有我要的JNDI名称,另外
    1、JNDI Explorer有错误
    如下配置:
    Service provider=jboss
    Initial contex factory=org.jnp.interfaces.NamingContextFactory
    Provider URl=jnp://localhost:1099
    Additional environment properties:(没有以下信息同样出错)
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099  java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    时出错
    The initial context could not be created:
    javax.naming.NoInitialContextException:cannot instantiate class:
    org.jnp.interfaces.NamingContextFactory[Root exception is java.lang.ClassNotFoundException:....2、getContext()方法可以执行,问题就处在getHome()里。3、
    我的jboss从新装了一遍,但一样有错。Eclipse+jboss需要配置jboss吗,java_home、jboss_home、classpath:..\tools.jar的环境变量都有阿,我参考的《Tutorial for building J2EE Applications using JBOSS and ECLIPSE 》,
      

  3.   

    4、 问题可能处在jBoss,部署的不对?我的步骤:
    CartBean右键Lomboz j2ee->Add EJB to module(CartEJB),CartEJB->j2ee Lomboz->Generate EJB class,Lomboz j2ee view中打开artEJB->Jboss3.2.1(右键)->Debug Server(控制台中有错),
    console:
    WARN  [NamingService] Context.PROVIDER_URL in server jndi.properties, url=localhost:1099WARN  [MainDeployer] The manifest entry in file:/E:/jboss-3.2.1/server/all/deploy/jboss-net.sar/commons-logging.jar          references URL file:/E:/jboss-3.2.1/server/all/deploy/jboss-net.sar/log4j.jar which could not be opened, entry ignoredWARN  [MainDeployer] The manifest entry in file:/E:/jboss-3.2.1/server/all/deploy/jboss-net.sar/commons-logging.jar          references URL file:/E:/jboss-3.2.1/server/all/deploy/jboss-net.sar/log4j-core.jar which could not be opened, entry ignoredWARN  [jbossweb] JSP compilation requires $JAVA_HOME/lib/tools.jar on your JBOSS_CLASSPATHWARN  [ServiceController] Problem creating service jboss:service=HAJNDI
    java.lang.NoClassDefFoundError: gnu/regexp/UncheckedREERROR [MainDeployer] could not create deployment: file:/E:/jboss-3.2.1/server/all/deploy/CartEJB.jar
    org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
    ERROR [URLDeploymentScanner] Failed to deploy: org.jboss.deployment.scanner.URLDeploymentScanner$DeployedURL@f82c4421{ url=file:/E:/jboss-3.2.1/server/all/deploy/CartEJB.jar, deployedLastModified=0 }
    org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.ERROR [URLDeploymentScanner] MBeanException: Exception in MBean operation 'checkIncompleteDeployments()'
    Cause: Incomplete Deployment listing:
    Packages waiting for a deployer:
      <none>
    Incompletely deployed packages:
    [org.jboss.deployment.DeploymentInfo@f82c4421 { url=file:/E:/jboss-3.2.1/server/all/deploy/CartEJB.jar }
      deployer: org.jboss.ejb.EJBDeployer@54cbb9
      status: Deployment FAILED reason: Verification of Enterprise Beans failed, see above for error messages.
      state: FAILED
      watch: file:/E:/jboss-3.2.1/server/all/deploy/CartEJB.jar
      lastDeployed: 1089785907607
      lastModified: 1089785908000
      mbeans:
    ]MBeans waiting for classes:
      <none>
    MBeans waiting for other MBeans:
    [ObjectName: jboss:service=HAJNDI
     state: FAILED
     I Depend On:   jboss:service=DefaultPartition Depends On Me: java.lang.NoClassDefFoundError: gnu/regexp/UncheckedRE]
    CartEJB(右键)->Deploy(应该没什么问题)
    ejb-jar:
             [jar] Building jar: F:\eclipse2.1\workspace\Cart\CartEJB\META-INF\CartEJB.jardeploy:
            [copy] Copying 1 file to E:\jboss-3.2.1\server\all\deploy
      

  4.   

    ERROR [URLDeploymentScanner] Failed to deploy: org.jboss.deployment.scanner.URLDeploymentScanner$DeployedURL@f82c4421{ url=file:/E:/jboss-3.2.1/server/all/deploy/CartEJB.jar, deployedLastModified=0 }显然,你的ejb部署失败!!WARN  [jbossweb] JSP compilation requires $JAVA_HOME/lib/tools.jar on your JBOSS_CLASSPATHWARN  [ServiceController] Problem creating service jboss:service=HAJNDI
    java.lang.NoClassDefFoundError: gnu/regexp/UncheckedRE这是jar文件找不到了。既然你说重新装了jboss还是有错,那么你有没有把需要的jar包放到eclipse的java build path里面阿(客户端也有很多jar哦),这些那本书上没有说吗?那本书我也看过,感觉太机械化了。刚开始学ejb最好所有的东西都自己试试看,包括xml编写,ejb打包等等。
    我的java build path有:
    j2ee.jar,jboss.jar,jbossall-client.jar,jboss-common.jar,jboss-transaction.jar,jnp-client.jar,log4j.jar,mysql-connector-..jar,servlet.jar
    当然对于你来说不一定都需要拉。看来还是dropship(飞翔的年代) 说的直接阿! 呵呵
    Never give up!
      

  5.   

    问题基本解决了,客户端运行正常,在环境变量里加了jboss_classpath:$JAVA_HOME/lib/tools.jar。这个问题我折磨我两个星期了,怪自己修行还浅呀,j2ee这条路曲折呀。
    ------------------- 我的java build path有:
    j2ee.jar,jboss.jar,jbossall-client.jar,jboss-common.jar,jboss-transaction.jar,jnp-client.jar,log4j.jar,mysql-connector-..jar,servlet.jar
    ---------------------
    java build path?不太明白,这些文件是建立j2ee project时加在Libraries里;还是加在环境变量里,classpath?推荐些j2ee方面的资料
    能否六个email,[email protected];)太感谢两位大侠了
      

  6.   

    ftp://218.28.64.19:22/
    用户名:javadown
    密码:javadown