你的上下文中,没有jndi服务器位置的位置信息,用jb自动生成一个测试客户端,看人家怎么写的就可以了

解决方案 »

  1.   

    你去web.xml文件中看是否有MyFirstTape这个jndi名字
      

  2.   

    getInitialContext(),获得jndi服务器位置的位置信息;要使用远程接口创建对象。
      

  3.   

    回qxxy_jan_jet(呆子):我用的就是jb自动生成的客房端程序,只不过它给的context.lookup()方法里没有参数,我自己给它加上我的Remote Interface:MyFirstTape.回bobopig(波波猪)和wangyihust(毅网):哪里能看到web.xml?是在bea的目录下,还是我当前的工程目录下,或是直接在jb里?但我没有找到。另外,你们说用“远程接口创建对象”,我想,我的确用的是“远程接口”。请看代码(只附了一部份,现在运行就卡在lookup那儿):
    public class MyFirstTapeTestClient1 extends Object {
      private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";
      private static final int MAX_OUTPUT_LINE_LENGTH = 100;
      private boolean logging = true;
      private MyFirstTapeHome myFirstTapeHome = null;
      private MyFirstTape myFirstTape = null;  //Construct the EJB test client
      public MyFirstTapeTestClient1() {
        initialize();
        create();
        helloWorld("You are the best!");
      }  public void initialize() {
        long startTime = 0;
        if (logging) {
          log("Initializing bean access.");
          startTime = System.currentTimeMillis();
        }    try {
          //get naming context
          Context context = getInitialContext();
          System.out.println("One");
          //look up jndi name
          /**@todo Provide a valid JNDI lookup name for the Home interface*/
          Object ref = context.lookup("MyFirstTape");
          System.out.println("Two");
          //look up jndi name and cast to Home interface
          myFirstTapeHome = (MyFirstTapeHome) PortableRemoteObject.narrow(ref, MyFirstTapeHome.class);
          System.out.println("Three");
          if (logging) {
            long endTime = System.currentTimeMillis();
            log("Succeeded initializing bean access through Home interface.");
            log("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          if (logging) {
            log("Failed initializing bean access.");
          }
          e.printStackTrace();
        }
      }
    ..........
      

  4.   

    你JB里找WEB-INF这个目录
    这里面就有web.xml文件
    或是你直接在你的应用所在的目录下找web-inf目录
    然后找出web.xml文件在web.xml里找到MyFirstTape的JNDI
    在此文件里你能找到类似下面的
      <servlet-mapping>
        <servlet-name>MyFirstTape</servlet-name>
        <url-pattern>???</url-pattern>
      </servlet-mapping><url-pattern>和</url-pattern>之间的就是你要的东西
      

  5.   

    另外你进入weblogic的控制台
    也能找到servlet的JNDI的
      

  6.   

    我想来想去,好象我做的没涉及到WEB-INF或是web.xml,因为我只建了个EJB和它的测试程序而无任何web tier(比如servlet,jsp)有关的东西。到是另外一个deployment descriptor会含有有关ejb的jndi的信息,只不过我找了半天也未找到。因我过去是用Sun One Application Server和Sun One Studio做EJB及部署的,很容易找到那些部署文件(xml)。所以问题还是未能解决,继续郁闷。谁能指点一下?
      

  7.   

    应该就是楼主部署的问题!
     web.xml中的问题!
      

  8.   

    问题我自己解决了,发现有两点值得大家注意:
    1)的确是部署的问题,但与web.xml完全不沾边,因为我没有web tier,只有项目中有JSP或Servlet等web conponent时才会涉及web.xml。真正有关的是:weblogic-ejb-jar.xml,它才是整个application的部署文件,里边有EJB的JNDI信息。
    2)我的问题重做了一次就解决了,与前次唯一的区别是:这回在创建Ejb Module时,我选的version是Ejb 2.0 Compliant而不是第一次选的Ejb 1.x Compliant。不知是否只是巧合,这样改动一下就解决问题。而且事后我又试了两次,选Ejb 1.x Compliant就是不行,与我前面的问题一样。此点,仅供参考!
      

  9.   

    确如楼主所说,与web.xml无关,jndi的信息全在weblogic-ejb-jar.xml