2 Replies Latest reply on Mar 2, 2002 2:35 PM by rohid

    Problem running Interest Client - javax.naming.NoInitialCont

    rohid Newbie

      I having troubling testing client application.
      I am getting javax.naming.NoInitialContextException

      C:\usr\lib\jboss>java -classpath c:\usr\lib\jboss\client\jnp-client.jar;
      \client\jboss-j2ee.jar;
      \client\jboss-client.jar;
      \client\jnp-client.jar;org\interest;
      \client\jndi.jar;. org.interest.InterestClient
      Got context
      javax.naming.NoInitialContextException: Need to specify class name in environmen
      t or system property, or as an applet parameter, or in an application resource f
      ile: java.naming.factory.initial




      All the required files are under c:\usr\lib\jboss\org\Interest
      InterestHome, InterestBean, Interest, InterestClient

      Interest.java
      package org.interest;
      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;

      public interface Interest extends EJBObject
      {

      public double calculateCompoundInterest(double principle,
      double rate, double periods) throws RemoteException;
      }


      InterestBean.java
      package org.interest;
      import java.rmi.RemoteException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;

      public class InterestBean implements SessionBean
      {

      public double calculateCompoundInterest(double principle,
      double rate, double periods)
      {
      System.out.println("Someone called `calculateCompoundInterest!'");
      return principle * Math.pow(1+rate, periods) - principle;
      }

      /** Empty method body
      */
      public void ejbCreate()
      {}

      public void ejbPostCreate()
      {}
      /** Empty method body
      */
      public void ejbRemove()
      {}
      /** Empty method body
      */
      public void ejbActivate()
      {}
      /** Empty method body
      */
      public void ejbPassivate()
      {}
      /** Empty method body
      */
      public void setSessionContext(SessionContext sc)
      {}
      }

      InterestHome.java
      package org.interest;
      import java.io.Serializable;
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;

      public interface InterestHome extends EJBHome
      {

      Interest create() throws RemoteException, CreateException;
      }


      InterestClient.java
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      import org.interest.Interest;
      import org.interest.InterestHome;


      class InterestClient
      {

      public static void main(String[] args)
      {

      try
      {
      // Get a naming context
      InitialContext jndiContext = new InitialContext();
      System.out.println("Got context");

      // Get a reference to the Interest Bean
      Object ref = jndiContext.lookup("interest/Interest");
      System.out.println("Got reference");

      // Get a reference from this to the Bean's Home interface
      InterestHome home = (InterestHome)
      PortableRemoteObject.narrow(ref, InterestHome.class);

      // Create an Interest object from the Home interface
      Interest interest = home.create();

      // call the calculateCompoundInterest() method to do the calculation
      System.out.println("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
      System.out.println(interest.calculateCompoundInterest(1000, 0.10, 2));
      }
      catch(Exception e)
      {
      System.out.println(e.toString());
      }
      }
      }

      ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar>
      JBoss Interest Sample Application
      <display-name>Interest EJB</display-name>
      <enterprise-beans>

      <ejb-name>Interest</ejb-name>
      org.interest.InterestHome
      org.interest.Interest
      <ejb-class>org.interest.InterestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>

      </enterprise-beans>
      </ejb-jar>

      <?xml version="1.0" encoding="UTF-8"?>

      <enterprise-beans>

      <ejb-name>Interest</ejb-name>
      <jndi-name>interest/Interest</jndi-name>

      </enterprise-beans>
      <resource-managers />

      <container-configurations>
      <container-configuration configuration-class="org.jboss.ejb.deployment.EntityContainerConfiguration">
      <container-name>BMP EntityBean</container-name>
      <container-invoker>org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker</container-invoker>
      <instance-pool>org.jboss.ejb.plugins.EntityInstancePool</instance-pool>
      <instance-cache>org.jboss.ejb.plugins.NoPassivationEntityInstanceCache</instance-cache>
      <persistence-manager>org.jboss.ejb.plugins.BMPPersistenceManager</persistence-manager>
      <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
      <container-invoker-conf>
      False
      </container-invoker-conf>
      <container-cache-conf />
      <container-pool-conf>
      100
      10
      </container-pool-conf>


        • 1. Re: Problem running Interest Client - javax.naming.NoInitial
          russell Newbie

          You need to specify some environment variables used by JNDI, in particular the values used in jndi.properties file (which must be in your classpath):

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.provider.url=jnp://localhost:1099
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

          You can also add these env properties to the command line using the java -D option.

          Please see the online docs for details.
          http://www.jboss.org/online-manual/HTML/ch01s15.html


          > I having troubling testing client application.
          > I am getting javax.naming.NoInitialContextException
          >
          > C:\usr\lib\jboss>java -classpath
          > c:\usr\lib\jboss\client\jnp-client.jar;
          > \client\jboss-j2ee.jar;
          > \client\jboss-client.jar;
          > \client\jnp-client.jar;org\interest;
          > \client\jndi.jar;. org.interest.InterestClient
          > Got context
          > javax.naming.NoInitialContextException: Need to
          > specify class name in environmen
          > t or system property, or as an applet parameter, or
          > in an application resource f
          > ile: java.naming.factory.initial
          >
          >
          >
          >
          > All the required files are under
          > c:\usr\lib\jboss\org\Interest
          > InterestHome, InterestBean, Interest, InterestClient
          >
          > Interest.java
          > package org.interest;
          > import javax.ejb.EJBObject;
          > import java.rmi.RemoteException;
          >
          > public interface Interest extends EJBObject
          > {
          >
          > public double calculateCompoundInterest(double
          > le principle,
          > double rate, double periods) throws
          > ows RemoteException;
          > }
          >
          >
          > InterestBean.java
          > package org.interest;
          > import java.rmi.RemoteException;
          > import javax.ejb.SessionBean;
          > import javax.ejb.SessionContext;
          >
          > public class InterestBean implements SessionBean
          > {
          >
          > public double calculateCompoundInterest(double
          > le principle,
          > double rate, double periods)
          > {
          > System.out.println("Someone called
          > alled `calculateCompoundInterest!'");
          > return principle * Math.pow(1+rate, periods) -
          > ds) - principle;
          > }
          >
          > /** Empty method body
          > */
          > public void ejbCreate()
          > {}
          >
          > public void ejbPostCreate()
          > {}
          > /** Empty method body
          > */
          > public void ejbRemove()
          > {}
          > /** Empty method body
          > */
          > public void ejbActivate()
          > {}
          > /** Empty method body
          > */
          > public void ejbPassivate()
          > {}
          > /** Empty method body
          > */
          > public void setSessionContext(SessionContext sc)
          > {}
          > }
          >
          > InterestHome.java
          > package org.interest;
          > import java.io.Serializable;
          > import java.rmi.RemoteException;
          > import javax.ejb.CreateException;
          > import javax.ejb.EJBHome;
          >
          > public interface InterestHome extends EJBHome
          > {
          >
          > Interest create() throws RemoteException,
          > n, CreateException;
          > }
          >
          >
          > InterestClient.java
          > import javax.naming.InitialContext;
          > import javax.rmi.PortableRemoteObject;
          > import org.interest.Interest;
          > import org.interest.InterestHome;
          >
          >
          > class InterestClient
          > {
          >
          > public static void main(String[] args)
          > {
          >
          > try
          > {
          > // Get a naming context
          > InitialContext jndiContext = new
          > xt = new InitialContext();
          > System.out.println("Got context");
          >
          > // Get a reference to the Interest Bean
          > Object ref =
          > t ref = jndiContext.lookup("interest/Interest");
          > System.out.println("Got reference");
          >
          > // Get a reference from this to the Bean's
          > e Bean's Home interface
          > InterestHome home = (InterestHome)
          > PortableRemoteObject.narrow(ref,
          > row(ref, InterestHome.class);
          >
          > // Create an Interest object from the Home
          > the Home interface
          > Interest interest = home.create();
          >
          > // call the calculateCompoundInterest()
          > terest() method to do the calculation
          > System.out.println("Interest on 1000 units,
          > 0 units, at 10% per period, compounded over 2 periods
          > is:");
          >
          >
          >
          >
          >
          >
          >
          >
          > System.out.println(interest.calculateCompoundInterest
          > 1000, 0.10, 2));
          > }
          > catch(Exception e)
          > {
          > System.out.println(e.toString());
          > }
          > }
          > }
          >
          > ejb-jar.xml
          > <?xml version="1.0" encoding="UTF-8"?>
          >
          > <ejb-jar>
          > JBoss Interest Sample
          > mple Application
          > <display-name>Interest EJB</display-name>
          > <enterprise-beans>
          >
          > <ejb-name>Interest</ejb-name>
          > org.interest.InterestHome
          > org.interest.Interest
          >
          >
          >
          >
          >
          > <ejb-class>org.interest.InterestBean</ejb-class>
          > <session-type>Stateless</session-type>
          > <transaction-type>Bean</transaction-type>
          >
          > </enterprise-beans>
          > </ejb-jar>
          >
          > <?xml version="1.0" encoding="UTF-8"?>
          >
          > <enterprise-beans>
          >
          > <ejb-name>Interest</ejb-name>
          > <jndi-name>interest/Interest</jndi-name>
          >
          > </enterprise-beans>
          > <resource-managers />
          >
          > <container-configurations>
          > <container-configuration
          > ration
          > configuration-class="org.jboss.ejb.deployment.EntityCo
          > tainerConfiguration">
          > <container-name>BMP EntityBean</container-name>
          >
          > <container-invoker>org.jboss.ejb.plugins.jrmp13.serve
          > .JRMPContainerInvoker</container-invoker>
          >
          > <instance-pool>org.jboss.ejb.plugins.EntityInstancePo
          > l</instance-pool>
          >
          > <instance-cache>org.jboss.ejb.plugins.NoPassivationEn
          > ityInstanceCache</instance-cache>
          >
          > <persistence-manager>org.jboss.ejb.plugins.BMPPersist
          > nceManager</persistence-manager>
          >
          > <transaction-manager>org.jboss.tm.TxManager on-manager>
          > <container-invoker-conf>
          > False
          > </container-invoker-conf>
          > <container-cache-conf />
          > <container-pool-conf>
          > 100
          > 10
          > </container-pool-conf>
          >
          >

          • 2. Re: Problem running Interest Client - javax.naming.NoInitial
            rohid Newbie

            I made some changes as suggested. I am now getting
            javax.naming.NameNotFoundException

            C:\usr\lib\jboss>java -classpath c:\usr\lib\jboss\client\jnp-client.jar;
            \client\jboss-j2ee.jar;
            \client\jboss-client.jar;
            \client\jnp-client.jar;org\interest;
            \client\jndi.jar;c:\examples\resources;. -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=localhost:1099 -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces org.interest.InterestClient
            Got context

            javax.naming.NameNotFoundException: interest not bound