5 Replies Latest reply on Apr 21, 2008 9:31 PM by juliaf

    Cannot instantiate class: org.jnp.interfaces.NamingContextF

    juliaf

      Hello

      I tried to deploy and run a simple EJB tester app on JBoss 5 beta using a SessionBean and I am getting the following exception
      -----------------------
      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory
      [Root exception is java.lang.ClassNotFoundException:org.jnp.interfaces.NamingContextFactory]
      -----------------------
      I have tried different approaches but with no luck.

      The structure of my simple_session.ear file deployed in %JBOSS_HOME%/server/default/deploy is this:

      simple_session/META-INF/Applicaiton.xml
      simple_session/META-INF/MANIFEST.MF
      simple_session/beans.jar
      simple_session/client.jar
      beans.jar consists of
      lemonpress\beans\SimpleSession.class
      lemonpress\beans\SimpleSessionBean.class
      META-INF\ejb-jar.xml
      META-INF\MANIFEST.MF
      client.jar consists of
      lemonpress\client\SimpleSessionClient.class
      META-INF\applicaiton-client.xml
      META-INF\MANIFEST.MF
      jndi.properties


      The source of lemonpress\client\SimpleSessionClient.class in client.jar
      package lemonpress.client;

      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import lemonpress.beans.SimpleSession;


      public class SimpleSessionClient {

      public static void main(String args[]) throws NamingException{

      System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url", "localhost:1099");
      System.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL, "localhost:8080");
      properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      InitialContext ctx = new InitialContext();
      SimpleSession ss = (SimpleSession) ctx.lookup(SimpleSession.class.getName());
      System.out.println("lookup returned " + ss.toString());
      String result = ss.getEchoString("It has worked");
      System.out.println(result);

      }
      }

      As a measure of desperation I also included the file
      jndi.properties in client.jar
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=jnp://localhost:1099

      and referenced it in client\META-INF\MANIFEST.MF
      Manifest-Version: 1.0
      Class-Path: beans.jar jndi.properties
      Main-Class: lemonpress.client.SimpleSessionClient

      initially I ran the project as

      simple_session> java -jar client.jar

      Then after reading about in forums (sadly, mostly relating to Jboss 4.x and not much on 5.x)
      I came to adding more and more code to the SimpleSessionClient.java and modifying way to run the client.jar
      to resolve this issue of binding the interface to the the JNDI Factory class that should return the missing Application Context.
      Apart from blown up code in the SimpleSessionClient
      other things that I tried include running the client.jar as
      A)
      simple_session> java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost:1099 -jar client.jar

      B)
      simple_session> set CLASSPATH=.;C:\jboss\client\jbossall-client.jar;C:\jboss\lib\concurrent.jar;C:\jboss\lib\jboss-common-core.jar;C:\jboss\lib\jboss-aop-jdk50.jar;C:\jboss\client\concurrent.jar;C:\jboss\client\jboss-common-client.jar;C:\jboss\client\jboss-javaee.jar;C:\jboss\client\jboss-transaction-client.jar;C:\jboss\client\jbosssx-client.jar;C:\jboss\client\jnp-client.jar;C:\jboss\server\default\lib\commons-httpclient.jar;C:\jboss\server\default\lib\jboss.jar;C:\jboss\server\default\lib\jboss-remoting.jar;C:\jboss\server\default\lib\jnpserver.jar;C:\jboss\server\default\deployers\ejb3.deployer\jboss-ejb3.jar;C:\jboss\server\default\deployers\jboss-aop-jboss5.deployer\jboss-aspect-library-jdk50.jar;

      simple_session> java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost:1099 -jar client.jar

      As you can see I tried a few different ways of including reference to JNDI to my client but with no avail.

      I start JBoss with default configuration and it does recognize and register my SimpleSessionBean in JNDI
      In startup output it gives only one WARN message
      17:02:27,265 WARN [QuartzTimerServiceFactory] sql failed: CREATE TABLE qrtz_job_details(JOB_NAME VARCHAR(80) NO
      T NULL, JOB_GROUP VARCHAR(80) NOT NULL, DESCRIPTION VARCHAR(120) NULL, JOB_CLASS_NAME VARCHAR(128) NOT NULL, IS_
      DURABLE VARCHAR(1) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, IS_STATEFUL VARCHAR(1) NOT NULL, REQUESTS_RECOVERY
      VARCHAR(1) NOT NULL, JOB_DATA BINARY NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP))
      However, later it says
      17:02:29,437 INFO [StdSchedulerFactory] Quartz scheduler 'JBossEJB3QuartzScheduler' initialized from an externally provided properties instance.
      17:02:29,437 INFO [StdSchedulerFactory] Quartz scheduler version: 1.5.2
      ....
      17:03:01,484 INFO [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'

      It binds JNDI
      17:02:25,328 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'

      And registers my SimpleSessionBean
      17:03:03,343 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:ear=simple_session.ear,jar=client.jar,name=client,service=EJB3 with dependencies:
      17:03:03,343 INFO [MCKernelAbstraction] and supplies:
      17:03:03,640 INFO [ClientENCInjectionContainer] STARTED CLIENT ENC CONTAINER: client
      17:03:08,062 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:ear=simple_session.ear,jar=beans.jar,name=SimpleSessionBean,service=EJB3 with dependencies:
      17:03:08,062 INFO [MCKernelAbstraction] and supplies:
      17:03:08,078 INFO [MCKernelAbstraction] Class:lemonpress.beans.SimpleSession
      17:03:10,812 INFO [EJBContainer] STARTED EJB: lemonpress.beans.SimpleSessionBean ejbName: SimpleSessionBean

      Could anyone help me to resolve this seemingly dead-end situation?

      Many thanks


        • 1. Re:  Cannot instantiate class: org.jnp.interfaces.NamingCont
          jaikiran

           

          simple_session> set CLASSPATH=.;C:\jboss\client\jbossall-client.jar;...

          simple_session> java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost:1099 -jar client.jar


          All you need is the jbossall-client.jar from the %JBOSS_HOME%/client folder to be present in the classpath of the client.
          And going by what you have posted, you seem to be doing that by setting the CLASSPATH. But, you are running a jar file using java -jar client.jar, in which case, the CLASSPATH is totally ignored.
          When running the jar file, you need to set the Classpath through the MANIFEST.MF file in the META-INF folder of the client.jar. Have a look at http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html to see how you can add classes/jars to the jar's classpath through the manifest file

          • 2. Re:  Cannot instantiate class: org.jnp.interfaces.NamingCont
            juliaf

            Many thanks, jaikiran, for your reply. Indeed the issue comes down to a missing librairy.

            I checked the link you gave, which was very helpful, but unfortunately I still failed to resolve the problem

            I tried several variants of the client's MANIFEST.MF

            a)
            Manifest-Version: 1.0
            Class-Path: beans.jar jndi.properties %JBOSS_HOME%/jbossall-client.jar
            Main-Class: lemonpress.client.SimpleSessionClient

            b)
            Manifest-Version: 1.0
            Class-Path: beans.jar jndi.properties C:/jboss/jbossall-client.jar
            Main-Class: lemonpress.client.SimpleSessionClient

            c)
            Manifest-Version: 1.0
            Class-Path: beans.jar jndi.properties lib/jbossall-client.jar
            Main-Class: lemonpress.client.SimpleSessionClient

            (all fererenced files are physically at those locations and the new line added at the end of MANIFEST.MF)

            Yet, in all cases I am getting the deployment error:
            *** DEPLOYMENTS IN ERROR: Name -> Error

            vfsfile:/C:/jboss/server/default/deploy/simple_session.ear -> java.io.IOException: invalid manifest format
            --------------------------------------
            more specifically:
            22:14:17,015 WARN [VFSStructureBuilder] Error populating deployment vfsfile:/C:/jboss/server/default/deploy/simple_session.ear
            org.jboss.deployers.spi.DeploymentException: Error populating context vfsfile:/C:/jboss/server/default/deploy/simple_session.ear
            at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
            at org.jboss.deployers.structure.spi.helpers.AbstractStructureBuilder.populateContext(AbstractStructureBuilder.java:144)
            at org.jboss.deployers.structure.spi.helpers.AbstractStructureBuilder.populateContext(AbstractStructureBuilder.java:83)
            at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:89)
            at org.jboss.deployers.plugins.main.MainDeployerImpl.determineStructure(MainDeployerImpl.java:743)
            at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:280)
            at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:237)
            at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:244)
            at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:131)
            .....
            Caused by: java.io.IOException: invalid manifest format
            at java.util.jar.Manifest.read(Manifest.java:193)


            Would you be so kind to let me know what is wrong with my classpaths?

            -------------------------------------
            Also when I add all 11 libraries to the classpath in the manifest
            I get a different kind of deployment error
            *** DEPLOYMENTS IN ERROR: Name -> Error
            vfsfile:/C:/jboss/server/default/deploy/simple_session.ear -> java.io.IOException: line too long

            This is worrying because assuming that my application grows I will probably need more libraries on the classpath
            Is there the way of circumventing this limitation?

            • 3. Re:  Cannot instantiate class: org.jnp.interfaces.NamingCont
              juliaf

              Sorry, there is a typo - a) & b) should read
              a)
              Manifest-Version: 1.0
              Class-Path: beans.jar jndi.properties %JBOSS_HOME%/client/jbossall-client.jar
              Main-Class: lemonpress.client.SimpleSessionClient

              b)
              Manifest-Version: 1.0
              Class-Path: beans.jar jndi.properties C:/jboss/client/jbossall-client.jar
              Main-Class: lemonpress.client.SimpleSessionClient

              • 4. Re:  Cannot instantiate class: org.jnp.interfaces.NamingCont
                jaikiran

                 

                Yet, in all cases I am getting the deployment error:
                *** DEPLOYMENTS IN ERROR: Name -> Error

                vfsfile:/C:/jboss/server/default/deploy/simple_session.ear -> java.io.IOException: invalid manifest format
                --------------------------------------
                more specifically:
                22:14:17,015 WARN [VFSStructureBuilder] Error populating deployment vfsfile:/C:/jboss/server/default/deploy/simple_session.ear




                You dont have to change anything in the EAR file. Let the EAR file be as it was earlier (when it was deploying properly).

                The changes you have to make is in the client.jar file which you are using to run the standalone client. The MANIFEST.MF file in that jar file should be edited to contain the Class-Path entry. The link that i posted in my earlier reply also mentions that

                Warning : The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


                Furthermore, the folder structure should look something like this:

                D:
                |
                |--- SomeFolder
                | |
                | |--- client.jar
                | | |
                | | |--- META-INF
                | | | |
                | | | |--- MANIFEST.MF
                | |
                | |
                | |--- jbossall-client.jar
                


                The MANIFEST.MF should contain something like:
                Main-Class: lemonpress.client.SimpleSessionClient
                Class-Path: jbossall-client.jar beans.jar
                
                


                Note that the jarpath that you specify in the Class-Path entry is relative to the jar file. So in this case, the jbossall-client.jar file will be searched in the same folder as client.jar. Please go through the documentation that i posted earlier, for more details.

                While posting the logs or xml content or code, remember to wrap it in a code block using the Code button in the message editor window and please hit the Preview button to make sure your post is correctly formatted

                • 5. Re:  Cannot instantiate class: org.jnp.interfaces.NamingCont
                  juliaf

                   

                  Hello, again
                  I had three issues with my code
                  1) I packaged the client into an ear, although it was just a stand-alone Java app.
                  
                  2) I incorrectly specified the JNDI connection, missing out the the protocol name "jnp" from "jnp://localhost:1099"
                  
                  3) In the lookup method I specified the name of the remote interface, rather then the actual bean (or a JNDI binding name). It works when the parameter is specified as
                  SimpleSession ss = (SimpleSession) ctx.lookup"SimpleSessionBean/remote");
                  and it doesn't when it is
                  SimpleSession ss = (SimpleSession) ctx.lookup(SimpleSession.class.getName());
                  
                  Strangely enough the latter was copied from Apress JEE5 tutorial.
                  I moved on to EJB relationships territory since then and recently posted another issue on the forum here: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=134147.
                  I will very much appreciate your help and many thanks for responding to this thread.