8 Replies Latest reply: Jun 9, 2009 7:17 AM by Wolfgang Knauf RSS

"NamingContextFactory class not found" error during deployme

Newbie

Hi all!

I have a legacy app I need to migrate from JBoss 3.2.7 to 5.1.0 GA.
I have found 13 problems so far and I resolved 12 of them.
The problem I have now is:
Jboss shows this error during startup:

INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
WARNING [collectionmgt] Error creating/registering StarcoreRootNode.
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)
 at com.starview.dm.collectionmgt.StarcoreRootNode.<init>(StarcoreRootNode.java:50)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27
)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
 at com.starview.support.startup.Startup.instantiateClasses(Startup.java:516)
 at com.starview.support.startup.Startup.loadStartupClasses(Startup.java:310)
 at com.starview.support.startup.Startup.access$200(Startup.java:50)
 at com.starview.support.startup.Startup$1.run(Startup.java:130)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:242)
 at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
 ... 12 more


I see jnpserver.jar is present in common\lib\ folder, so don't really understand why this file can't be found. I also tried to copy jnpserver.jar to my_server\lib folder, but it didn't help.

I'm using Windows XP SP3, Sun JDK 1.5.0_18, JBoss AS 5.1.0 GA.
Which other info should I provide so it would be easier to help me? the startup script we use? jboss config files? jboss or app lib folder contents?

  • 1. Re:
    jaikiran pai Master

     

    "alskor" wrote:

    I have found 13 problems so far and I resolved 12 of them.

    LOL :)


    The problem I have now is:
    Jboss shows this error during startup:

    INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
    WARNING [collectionmgt] Error creating/registering StarcoreRootNode.
    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)
     at com.starview.dm.collectionmgt.StarcoreRootNode.<init>(StarcoreRootNode.java:50)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27
    )
     at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
     at com.starview.support.startup.Startup.instantiateClasses(Startup.java:516)
    


    Looks like the com.starview.support.startup.Startup's instantiateClasses is trying to invoke some constructor? Can you post the relevant code? Also why is it that the application specific code is trying to instantiate this class?


  • 2. Re:
    Newbie

     

    "jaikiran" wrote:

    Looks like the com.starview.support.startup.Startup's instantiateClasses is trying to invoke some constructor? Can you post the relevant code? Also why is it that the application specific code is trying to instantiate this class?

    here's that line, where exception is being thrown (line 516), although I don't think it would help:
    startupObject = withPropFileConstructor.newInstance(args);
    

    the code loads some startup classes in that method and one of them requires a context initialization, which can't be performed because (I guess) the proper JAR file is not visible to the current classloader (why??).
    It's an old legacy app and I can't really change much in this scheme. It works properly with Jboss 3.2.7.
    My guess is I need to reference the jar file with that NamingContextFactory somewhere in Jboss config file. But it is already present in jboss common\lib\ folder and my current conf\jboss-service.xml has standard references to load default Jboss libs:

    <classpath codebase="${jboss.server.lib.url}" archives="*"/>
     <classpath codebase="${jboss.common.lib.url}" archives="*"/>
    


    so, what could be a reason for this class not being visible?

  • 3. Re:
    Newbie

    this is the actual line, which causes the problem:

    InitialContext ctx = new InitialContext();


  • 4. Re:
    Newbie

    interesting:
    I added this code right in front the InitialContext creation:

    // new code
     String className = "org.jnp.interfaces.NamingContextFactory";
     System.out.println("trying to load class: " + className);
     Class c = Class.forName(className);
    
     System.out.println("loaded class: " + c + " methods: " + c.getMethods().length);
    
     // old code
     InitialContext ctx = new InitialContext();
    


    the output is:
    [STDOUT] trying to load class: org.jnp.interfaces.NamingContextFactory
    [STDOUT] loaded class: class org.jnp.interfaces.NamingContextFactory methods: 11


    so, apparently NamingContextFactory class IS loaded and visible to the current class loader. then why in the world isn't it visible one line below, when I try "new InitialContext()" ??

    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Roo
    t 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)
     at com.starview.dm.collectionmgt.StarcoreRootNode.<init>(StarcoreRootNode.java:54)


  • 5. Re:
    Newbie

    I changed jndi.properties to have default "Standard config" values:

    java.naming.factory.initial=org.jboss.iiop.naming.ORBInitialContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    


    and now I'm back to where I started when I copied "standard" config to my own and then copied my EARs and services xml configs:
    javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.iiop.naming.ORBInitialContextFacto
    ry [Root exception is java.lang.ClassNotFoundException: org.jboss.iiop.naming.ORBInitialContextFactory]
     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)
     at com.starview.dm.collectionmgt.StarcoreRootNode.<init>(StarcoreRootNode.java:54)
    .......
    .......
    Caused by: java.lang.ClassNotFoundException: org.jboss.iiop.naming.ORBInitialContextFactory
     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:242)
     at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
    
    



  • 6. Re:
    Wolfgang Knauf Master

    Hi,

    please describe what you are doing. What is the class "com.starview.support.startup.Startup" used for? Is it a servlet or a JMX bean? Or is it a standalone application client?

    Do you have a file "jndi.properties" in your app? If yes: you don't need it if the app is running in the server, because there are default properties which point to the local jndi.

    And finally: does your app package any JBoss jar or class, maybe from the old 3.2.7? If yes, those will conflict with the current ones.

    Hope this helps

    Wolfgang

  • 7. Re:
    Newbie

     

    "Wolfgang Knauf" wrote:
    Hi,
    please describe what you are doing. What is the class "com.starview.support.startup.Startup" used for? Is it a servlet or a JMX bean? Or is it a standalone application client?

    I have 3 applications (2 EARs and 3 SAR), which I'm trying to deploy. it all worked fine with JBoss 3.2.7, but fails with Jboss 5.1.0GA. "Startup" class inits some stuff :) - it breaks when trying to create an instance of InitialContext.
    This "Startup" is a part of the EAR application, it's not a client app.
    It's executed on startup when JBoss loads the corresponding xml file (jboss\server\starcore\deploy\sv-dm-service.xml) - so, yeah, it's declared as MBean:
    sv-dm-service.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <server>
     <classpath codebase="lib/ext" archives="discovery.jar"/>
     <mbean code="com.starview.support.startup.Startup" name="starview.startup:type=Manager,name=DM-Startup">
     <depends>jboss:service=Naming</depends>
     <depends>jboss.j2ee:jndiName=ejb/NodeServer,service=EJB</depends>
     <depends>jboss.j2ee:jndiName=ejb/PropertyManagerLocal,service=EJB</depends>
     <attribute name="StartupClasses">
     com.starview.dm.collectionmgt.StarcoreRootNode, com.starview.dm.database.sink.Startup, com.starview.dm.adaptor.core.AdaptorManagerImpl$Startup, com.starview.dm.soap.provider.Startup
     </attribute>
     </mbean>
    </server>
    


    I also tried adding
     <classpath codebase="lib" archives="jbossall-client.jar"/>
    


    to the libs list for this service, but this didn't help.

    "Wolfgang Knauf" wrote:

    Do you have a file "jndi.properties" in your app? If yes: you don't need it if the app is running in the server, because there are default properties which point to the local jndi.

    And finally: does your app package any JBoss jar or class, maybe from the old 3.2.7? If yes, those will conflict with the current ones.

    I do have "jndi.properties" in my jboss/server/starcore/conf folder. without this file, the server startup fails. I'm using the default one, which has:
    # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
    #
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    

    I also tried another variant, which I copied from "standard" jboss server config:
    # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
    #
    java.naming.factory.initial=org.jboss.iiop.naming.ORBInitialContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    


    But there's no difference, the second variant gives the same "class not found" error, the only difference is that org.jboss.iiop.naming.ORBInitialContextFactory is not found instead of org.jnp.interfaces.NamingContextFactory.

    about old jboss classes - yes, it's very likely that there are some old jboss classes hidden somewhere because I have tons of WAR files there with a bunch of jars. but I'd expect to get "class cast exception" or "class incompatible" or something similar in this case, and not just "class not found".

    so, again- you can see in my example that I can create an instance of that class:
     String className = "org.jnp.interfaces.NamingContextFactory";
     Class c = Class.forName(className);
     System.out.println("loaded class: " + c + " methods: " + c.getMethods().length);
    

    - this works FINE. which means that that factory class IS visible to the class loader, which works with this particular class. but in the NEXT (!) line it all breaks
     // old code
     InitialContext ctx = new InitialContext();
    


  • 8. Re:
    Wolfgang Knauf Master

    Hi,

    where in your MBean is this code snippet located? In the constructor or in some MBean lifecycle method?

    I suggest that you try to extract your MBean to a new project and strip it off all code besides the "new InitialContext();" call. This should work. If you know that it works, you know that there is another problem with your project (maybe some old class bundled). It it does not work either, you can repost it here.

    Hope this helps

    Wolfgang