很简单的,myeclipse配置好就行了,不要.bat的,按照他的向导走

解决方案 »

  1.   

    谢谢,部署EJB我已经会了,但是怎么写客户端调用自己部署的EJB呢?我不会,牵涉到.PROPERTIES文件的写法和JNDI的使用。请详细解释一下好吗?谢谢了。
      

  2.   

    给个demo:
    package jbejb;import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.util.*;public class SayHelloTestClient1 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 SayHelloHome sayHelloHome = null;
      private SayHello sayHello = null;  //Construct the EJB test client
      public SayHelloTestClient1() {
        initialize();
      }
      private static Context getInitialContext() throws NamingException {
         Hashtable environment = new Hashtable();
         environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
         environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
         environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
         return new InitialContext(environment);
       }  public void initialize() {
        long startTime = 0;
        if (logging) {
          log("Initializing bean access.");
          startTime = System.currentTimeMillis();
        }    try {
          //get naming context
          Context context = this.getInitialContext();      //look up jndi name
          Object ref = context.lookup("SayHello");
          //look up jndi name and cast to Home interface
          sayHelloHome = (SayHelloHome) PortableRemoteObject.narrow(ref, SayHelloHome.class);
          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();
        }
      }  //----------------------------------------------------------------------------
      // Methods that use Home interface methods to generate a Remote interface reference
      //----------------------------------------------------------------------------  public SayHello create() {
        long startTime = 0;
        if (logging) {
          log("Calling create()");
          startTime = System.currentTimeMillis();
        }
        try {
          sayHello = sayHelloHome.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(): " + sayHello + ".");
        }
        return sayHello;
      }  //----------------------------------------------------------------------------
      // Utility Methods
      //----------------------------------------------------------------------------  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) {
        SayHelloTestClient1 client = new SayHelloTestClient1();
        try{
            SayHello hi=client.create();
            System.out.println(hi.sayHello());
        }
        catch(Exception e){
          e.printStackTrace();
        }
        // Use the client object to call one of the Home interface wrappers
        // above, to create a Remote interface reference to the bean.
        // If the return value is of the Remote interface type, you can use it
        // to access the remote interface methods.  You can also just use the
        // client object to call the Remote interface wrappers.
      }
    }
      

  3.   

    那么要写jboss-service.xml吗?.property文件怎么写?谢谢.
      

  4.   

    无状态的sessionbean搞定了,好像不需要写什么properties文件。但是有一点我还是不清楚,像tomcat中配置数据连接池的时候,有
    Context ctx=new InitialContext("java:comp/env");
    这一句是怎么出来的?“java:comp/env”在哪里定义的?可以自行定义别的吗?好像jboss中也是这么做的。希望各位高手解答。