11 Replies Latest reply on Oct 5, 2015 2:51 AM by hmohammedrajjaz

    java.lang.ClassNotFoundException: org.jnp.interfaces.NamingC


      JBoss 4.0.4-CR2, EJB 3.0

      I have a client which accesses EJB's successfully when I create the InitialContext as follows:

       ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      However, if I place these properties in a jndi.properties file, instead, under a folder and include this folder in the classpath


      I get the error:

      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ]
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
       at javax.naming.InitialContext.init(InitialContext.java:223)
       at javax.naming.InitialContext.<init>(InitialContext.java:175)

      I'd like to use a jndi.properties file instead of doing it in the code.

      I'd appreciate any suggestions on why this might be happening.


        • 1. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

          There must be a disconnect between where you placed the file and the classpath. How are you starting the client? Via Eclipse, NetBeans, Ant, command line? Also, exactly where are you placing the properties file and exactly what is the classpath?

          Are you creating a jar file that contains the client classes? If so, you could place the jndi.properties file in the base directory of the jar file. That should work.

          • 2. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

            This happens, both, when I run the client in Eclipse or by using Ant.

            All the client classes, including the one with main() method are packaged in a jar file which is included in the classpath.

            I place jndi.properties in c:\Temp and specify c:\Temp in classpath. It seems that this properties file is visible because the exception does mention the NamingContextFactory. If this file is not visible I get the error saying that the environment property should be specified.

            I'd like to have this property file outside a jar so it can be replaced without replacing the jar.

            I'd appreciate any ideas.


            • 3. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

              Which JBoss client jar files are you including in your client's classpath?

              • 4. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

                Here is an excerpt from build.xml. myClient.jar are my classes. Classpath must be ok as things work when I place the JNDI variables in system variables!

                 <path id="client.classpath">
                 <fileset dir="${build.dir}/jar">
                 <include name="myClient.jar" />
                 <pathelement location="c:/Temp" />
                 <!--<path refid="build.classpath"/>-->
                 <fileset dir="${client.lib}">
                 <include name="jbossall-client.jar" />
                 <include name="jboss-aop-jdk50-client.jar" />
                 <include name="jboss-aspect-jdk50-client.jar" />
                 <include name="jboss-common-client.jar" />
                 <include name="jbossall-client.jar" />
                 <target name="runClient" depends="package-client">
                 <echo message="Client lib= ${client.lib}"/>
                 <property name="clientClasspath" refid="client.classpath"/>
                 <echo message="Client classpath= ${clientClasspath}"/>
                 <java classname="com.Client" classpathref="client.classpath" fork="true">


                • 5. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

                  Let's try one more thing. Set this environment variable:

                  set _JAVA_LAUNCHER_DEBUG=1

                  Add the 'output' attribute to the < java > task so that you can capture the program output in a file. In addition, add the -verbose:class JVM argument. So the < java > task would look like:

                  <java classname="com.Client" classpathref="client.classpath" fork="true" output="output.txt">
                   <jmvarg value="-verbose:class" />

                  If you have problems with the above steps, run your client from the command line (instead of within Ant), and redirect stdout to a file.

                  The resulting output will be too long to post, so email it to me (click on my name in the Author column to see my email address).

                  Another suggestion is to write a very simple client that does nothing but get the initial context and request the EJB. If that works, then there is something about your client that is causing a class loader issue.

                  • 6. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

                    Similar problem, however, I'm using portlets, running things inside the same JVM and everything runs inside the same app, however, in some places my app uses

                    TransactionManager tm = (TransactionManager)new InitialContext().lookup("java:/TransactionManager") ;

                    ... wich runs nice and smooth, while some other places, INSIDE THE VERY SAME APPLICATION, with the very same identical code, print this error:

                    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org/jnp/interfaces/NamingContextFactory]
                     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
                     at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                     at javax.naming.InitialContext.init(InitialContext.java:223)
                     at javax.naming.InitialContext.<init>(InitialContext.java:175)
                     at portlets.performers.ActionPerformer.flushPersistence(Unknown Source)
                     at portlets.performers.ActionPerformer.finalize(Unknown Source)
                     at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
                     at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
                     at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
                     at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
                    Caused by: java.lang.ClassNotFoundException: org/jnp/interfaces/NamingContextFactory
                     at java.lang.Class.forName0(Native Method)
                     at java.lang.Class.forName(Class.java:247)
                     at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
                     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
                     ... 9 more

                    ... weird, huh ?

                    • 7. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

                      I am stumped. Based on the output you sent me, it should work. The C:\jboss-4.0.4.CR2\client\jbossall-client.jar, which contains the org.jnp.interfaces.NamingContextFactory is in the class path, so there should be no problem in finding and loading that class. It is almost as if, suddenly, another class loader was invoked, one which did not know about the classpath.

                      All I can suggest is to try it from the command line (to eliminate Eclipse messing something up), and to also try a simpler program that only looks up the EJB in jndi (you should be able to get by with a much shorter classpath and thus be able to more easily run it manually from the command line).

                      • 8. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.Nam

                        i'm having the same problem, anyone knows the solution to this?


                        • 9. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingC

                          Hi guys,


                          i have encountered this problem today too.

                          this is what i do to fix this problem, maybe useful for you and other guys.

                          i just add all the jar files in the client folder of jboss directory.

                          • 10. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingC

                            Hi Developers,


                                I am also facing the same problem, Can Anyone share me, If you have fixed it.




                            • 11. Re: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingC

                              i had same issue but i solved through add the library called jbossall-client.jar