catch (Exception e)
{ }
这句问题最大:异常CATCH了而不处理,怎么知道出什么错呢?
至少改成:
catch (Exception e)
{
                        e.printStackTrace();
}
先看下出了什么问题先。

解决方案 »

  1.   

    FT楼上,你难道当写程序是赌博?赌它不会出错?那JAVA的异常机制拿来做什么?
    就是为了让你多写一个TRY{}CATCH块??
    成功了只能算你运气。
      

  2.   

    对新手来说 ,一般的问题可能是没有发布Ejb或当前ejb不是最新的(误用了以前的Ejb) ,请楼主再仔细查查。
    1. 调试Object obj=ctx.lookup("Hello");语句 ,如果为null, 则没有发布Ejb或ejb发布时不成功。
    2. 如果obj不为null, 则有可能ejb不是最新的ejb.
    public class HelloClient
    {
      public static void main(String[] args)
      {
    try
    {
    InitialContext ctx=new InitialContext();
    Object obj=ctx.lookup("Hello");
             if (obj == null) {
                System.out.println("ejb没有发布成功!");
             }
    HelloHome home=(HelloHome)javax.rmi.PortableRemoteObject.narrowobj,HelloHome.class);
    Hello hl=home.create();
             if (h1 == null) {
                System.out.println("不能创建remote home对象");
             }
             String sReturn = hl.getHello();
             if (sReturn == null) {
                System.out.println("ejb的可能getHello()方法中没有动作或不是最新的ejb,请进行编译,发布,运行")
             }
    System.out.println(sReturn);
    }
    catch (Exception e)
    {
              System.out.println(e);
    }
    }
    }
      

  3.   

    我按照各位底指点做了,系统打印错误:
    javax.naming.NoInitialContextException: need to specify class name in environment
    or system property or as an ...
    这个错误什么意思,是描述xml写错了吗?
      

  4.   

    给你参考一下:
    // HelloWorldClient.java
    package hello;
    import java.io.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.util.Properties;public class HelloWorldClient
    {
    private static Context getInitialContext() throws Exception {
    String url = "t3://localhost: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;
    }
    } public static void main(String[] args)
    throws Exception
    {
    HelloWorldHome helloWorldHome;
    HelloWorld theHelloWorld;
    // Look up home interface
    // InitialContext ctx = new InitialContext();
    Context ctx = getInitialContext();
    Object objref = ctx.lookup("Hello");
    helloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(objref, HelloWorldHome.class);
    // Create bean instance
    theHelloWorld = helloWorldHome.create();
    // Call business method.
    String result = theHelloWorld.helloWorld();
    System.out.println("HelloWorldBean.helloWorld(): " + result);
    }
    }
      

  5.   

    再问个问题:如何知道ejb已经部署成功,
    如果在 weblogic console server 中的 mydomain>ejb deployments 的列表里出现了该ejb是不是就已经成功了
      

  6.   

    在EJB部署成功时会出现类似如下的信息:
    C:\bea\jdk131_03\bin\javaw  -classpath C:\bea\weblogic700\server\lib\weblogic_sp.jar;C:\bea\weblogic700\server\lib\weblogic.jar;C:\bea\weblogic700\server\lib\webservices.jar; weblogic.Deployer  -user system  -adminurl http://liuyi:7001  -password 12345678  -activate  -name proBoreWellLiquid -upload  -source D:/KDCERP/EJBjar/proBoreWellLiquid.jar -targets myserver
    Operation started, waiting for notifications...
    #TaskID Action Status Target Type Application Source
    6 Activate Started myserver Server proBoreWellLiquid C:\bea\user_projects\mydomain\myserver\upload\proBoreWellLiquid\proBoreWellLiquid.jar
      

  7.   

    你是错误提示你InitialContext ctx=new InitialContext();有错 ,按liad的方法试试。
    发布成与否 ,都会在weblogic console server 中的 mydomain>ejb deployments显示发布的ejb。 但如果发布成功 ,它对应中提示Complete.如果不成功, 它会显示为fail
      

  8.   

    Error processing file 'META-INF/weblogic-ejb-jar.xml'. weblogic.xml.process.XMLProcessingException: XML document does not appear to contain a properly formed DOCTYPE header - with nested exception: [weblogic.xml.process.ProcessorFactoryException: XML document does not appear to contain a properly formed DOCTYPE header] 我的ejb-jar.xml里好像有问题,上面是错误提示,应该怎么改呀
      

  9.   

    String url = "t3://你的机器IP:7001";
    String user = 你的数据库用户名;
    String password = 你的密码;
      

  10.   

    ejb-jar.xml前面几行<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
    <ejb-jar>weblogic-ejb-jar.xml前面几行<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN' 'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'><weblogic-ejb-jar>或者<?xml version="1.0"?><!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'>
    <weblogic-ejb-jar>