客房端程序:import javax.naming.*;
import javax.rmi.PortableRemoteObject;public class TimeFunctionsTestClient1
{
  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 TimeFunctionsHome timeFunctionsHome = null;
  private TimeFunctions timeFunctions = null;  //Construct the EJB test client
  public TimeFunctionsTestClient1()
  {
    long startTime = 0;
    if (logging)
    {
      log("Initializing bean access.");
      startTime = System.currentTimeMillis();
    }    try
    {
      //get naming context
      Context ctx = new InitialContext();      //look up jndi name
      Object ref = ctx.lookup("TimeFunctions");      //cast to Home interface
      timeFunctionsHome = (TimeFunctionsHome) PortableRemoteObject.narrow(ref, TimeFunctionsHome.class);
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded initializing bean access.");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed initializing bean access.");
      }
      e.printStackTrace();
    }
  }  public TimeFunctions create()
  {
    long startTime = 0;
    if (logging)
    {
      log("Calling create()");
      startTime = System.currentTimeMillis();
    }
    try
    {
      timeFunctions = timeFunctionsHome.create();
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded: create()");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed: create()");
      }
      e.printStackTrace();
    }    if (logging)
    {
      log("Return value from create(): " + timeFunctions + ".");
    }
    return timeFunctions;
  }  public long getTimes()
  {
    long returnValue = 0;
    if (timeFunctions == null)
    {
      System.out.println("Error in getTimes(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging)
    {
      log("Calling getTimes()");
      startTime = System.currentTimeMillis();
    }    try
    {
      returnValue = timeFunctions.getTimes();
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded: getTimes()");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed: getTimes()");
      }
      e.printStackTrace();
    }    if (logging)
    {
      log("Return value from getTimes(): " + returnValue + ".");
    }
    return returnValue;
  }  private void log(String message)
  {
    if (message == null)
    {
      System.out.println("-- null");
      return ;
    }
    if (message.length() > MAX_OUTPUT_LINE_LENGTH)
    {
      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
    }
    else
    {
      System.out.println("-- " + message);
    }
  }
  //Main method  public static void main(String[] args)
  {
    TimeFunctionsTestClient1 client = new TimeFunctionsTestClient1();
    client.create();
   // client.getTimes();
  }
}

解决方案 »

  1.   

    从异常来看应该是你的jbuilder中的CORBA选项没有配置好。
      

  2.   

    Context ctx = new InitialContext();
    的初始化方式改为:(要import java.util.*) Properties properties = null;
     properties = new Properties();
     properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
     properties.put(Context.PROVIDER_URL, "t3://localhost:7001");//此处是你EJB服务器的位置
     InitialContext context = new InitialContext(properties);
      

  3.   

    Tool-->EnterpriseSetup-->CORBA-->Configuration我选择了VisiBroker(Edit一项的设置为:Path for ORB tools是:E:/BorlandEnterpriseServer/bin;Library for properties是:Borland Enterprise Server 5.0 Client)
      

  4.   

    在Tools->Enterprise Setup->CORBA标签页里,点Configuration右边的New...,增加一个weblogic的项; 在Path for ORB tools下,加入Weblogic的目录;在Library for projects下,点"..."加入 Weblogic6.x deploy 的库;在compiler command 填上idlj.exe;在Command option for output directory 填上一个目录路径,但是要注意的是,不能是中文、带空格。
      

  5.   

    流浪的风,改后出现如下错误。
    javax.naming.CommunicationException.  Root exception is java.net.ConnectException: No server found at HTTP://cgserver2:7001
    at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:155)
    at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:207)
            at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:261)-- Failed initializing bean access.
    at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:203)
    at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:124)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:665)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246)
    at javax.naming.InitialContext.init(InitialContext.java:222)
    at javax.naming.InitialContext.<init>(InitialContext.java:198)
    at sbtutorial.TimeFunctionsTestClient1.<init>(TimeFunctionsTestClient1.java:33)
    at sbtutorial.TimeFunctionsTestClient1.main(TimeFunctionsTestClient1.java:163)
    java.lang.NullPointerException-- Calling create()
    -- Failed: create()
    at sbtutorial.TimeFunctionsTestClient1.create(TimeFunctionsTestClient1.java:70)
    at sbtutorial.TimeFunctionsTestClient1.main(TimeFunctionsTestClient1.java:164)
    -- Return value from create(): null.
      

  6.   

    头越来越大了。
    小程设置以后出现。
    "SBTutorial.jpx": Invocation Error.  Check your CORBA configuration using Tools | Enterprise Setup... | CORBA.  Also check IDL settings on the Project | Project Properties | Build | IDL page
      

  7.   

    在Project | Project Properties | Build | IDL page中将idl设置为CORBA configuration中建立的weblogic项试一下。