2 Replies Latest reply on Feb 21, 2017 8:14 AM by andey

    EAP 7 java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory but it is in rt.jar in the jdk 1.8

    swarsa

      I have installed a RAR file from webMethods and now just getting an error: "java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory".  This is strange. The boot classpath of JBOSS AS contains the jar containing the class that is reported as not found (I found this by using EAP_HOME/bin/jconsole.bat):

       

      C:\Java\jdk1.8.0_112\jre\lib\resources.jar;C:\Java\jdk1.8.0_112\jre\lib\rt.jar;C:\Java\jdk1.8.0_112\jre\lib\sunrsasign.jar;C:\Java\jdk1.8.0_112\jre\lib\jsse.jar;C:\Java\jdk1.8.0_112\jre\lib\jce.jar;C:\Java\jdk1.8.0_112\jre\lib\charsets.jar;C:\Java\jdk1.8.0_112\jre\lib\jfr.jar;C:\Java\jdk1.8.0_112\jre\classes

       

      in the startup log, I see this:

       

      2017-02-14 10:40:06,486 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-7) Adding dependency ModuleDependency [identifier=sun.jdk:main, moduleLoader=local module loader @66133adc (finder: local module finder @7bfcd12c (roots: C:\jboss-devstudio\runtimes\jboss-eap\modules,C:\jboss-devstudio\runtimes\jboss-eap\modules\system\layers\base)), export=false, optional=false, importServices=true] to module deployment.webm-jmsra.rar:main

       

      And there is a module sun.jdk at EAP_HOME/modules/system/layers/base/sun/jdk/main

       

      <module xmlns="urn:jboss:module:1.3" name="sun.jdk">

          <resources>

              <!-- currently jboss modules has not way of importing services from

              classes.jar so we duplicate them here -->

              <resource-root path="service-loader-resources"/>

          </resources>

          <dependencies>

              <module name="sun.scripting" export="true"/>

             <system export="true">

                  <paths>

                      <path name="com/sun/image/codec/jpeg"/>

                      <path name="com/sun/imageio/plugins/bmp"/>

                      <path name="com/sun/imageio/plugins/common"/>

                      <path name="com/sun/imageio/plugins/gif"/>

                      <path name="com/sun/imageio/plugins/jpeg"/>

                      <path name="com/sun/imageio/plugins/png"/>

                      <path name="com/sun/imageio/plugins/wbmp"/>

                      <path name="com/sun/imageio/spi"/>

                      <path name="com/sun/imageio/stream"/>

                      <path name="com/sun/jndi/dns"/>

       

                     <path name="com/sun/jndi/ldap"/>

       

      As you can see, it has the path of the class file.  Because of this, I do not see why this class is not visible.  What do I need to do to make it visible?

       

      Thanks,

      Steve

       

      java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory

        • 1. Re: EAP 7 java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory but it is in rt.jar in the jdk 1.8
          swarsa

          I answered my own question.  I had 4 JNDI properties on 4 separate lines:

           

          java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory

          java.naming.provider.url=ldap://xxx.yyy.zzz:nnn

          java.naming.security.principal=cn=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx

          java.naming.security.credentials=xxx

           

          Once I moved them all onto one line, I no longer got the ClassNotFoundException:

           

          java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory,java.naming.provider.url=ldap://xxx.yyy.zzz:nnn

           

          However, since the java.naming.security.principal has comma's embedded in it, I can't make that part of a comma delimited string.

          • 2. Re: EAP 7 java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory but it is in rt.jar in the jdk 1.8
            andey

            Hi,

             

            JBoss Modules is building up what is in the classloader from scratch, see javax.api $JBOSS_HOME/modules/javax/api/modules.xml

            - this module contains the javax.* packages you can see them listed. The reason this is done is to allow different implementations to be used. For example JAXP which is javax.xml.... and implemented by Xerces (in JDK or in JBoss), so a module pretty much has full control over what it can see.

             

            com.sun.jndi.ldap.LdapCtxFactory is a JDK specific class, which means using this class directly makes your code not portable to a different JDK implementation. Where as if you only depend on the javax.api module, then your application would be portable to other JDK implementations.

             

             

            Add a dependency on the module: sun.jdk such as:

             

            ~~~

            <module xmlns="urn:jboss:module:1.1" name="spring.ldap">

                <resources>

                    <resource-root path="spring-ldap-core-1.3.0.jar"/>

                </resources>   

                <dependencies>

                    <module name="javax.api" export="true"/>

                    <module name="sun.jdk" export="true"/>

                    <module name="javaee.api" export="true"/>

                    <module name="org.apache.commons.logging"/>

                    <module name="spring" slot="2.5.6"/>

                    <module name="spring.security"/>

                </dependencies>

            </module>

            ~~~