2 Replies Latest reply on Jul 9, 2004 7:11 PM by Christopher Spiteri

    Accessing EJB from a Java standalone app with main()

    Christopher Spiteri Newbie

      I have an EJB deployed successfully in a JAR, which is in turn deployed in an EAR in JBoss. I can access the EJB's methods from an JSP deployed in a WAR file in the same EAR. However, when I try to use the same JNDI name to access the EJB from a standalone Java application (just a class with simple main() function) using this code:


      /* class imports here...*/

      public class EJBInvoker {
      public static void main(String[] args) {

      Category myCategory = null; // remote interface
      CategoryHome myCategoryHome = null; // home interface

      try {
      Context context = new InitialContext();
      myCategoryHome = (CategoryHome)PortableRemoteObject.narrow(Context.lookup("CategoryBean"), CategoryHome.class);
      Integer primaryKey = new Integer(8); // just an integer for primarykey
      myCategory = (Category)myCategoryHome.findByPrimaryKey(primaryKey);
      System.out.println(myCategory.getName());

      } catch (Exception ex) {
      System.out.println("Error: "+ ex.getMessage());
      ex.printStackTrace();
      }
      }
      }

      I get the following error:

      Error: Can't find SerialContextProvider
      javax.naming.CommunicationException: Can't find SerialContextProvider
      at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
      a:63)
      at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:120
      )
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.mtmalta.ejb.testing.EJBInvoker.main(EJBInvoker.java:22)

      Can anyone turn the light switch on for me pls?! Thanks!