8 Replies Latest reply on Apr 13, 2012 1:16 PM by guinotphil

    sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException

    asfhy

      I am updating an old application here on my office server. The app uses an ODBC with a Microsoft Access database as data store. On the same machine I have installed a JBossAS 6 instance and a JBossAS 7 instance. Both having the default config, only unzipped the distribution downloaded.

       

      When I start my application in JBossAS 6 it runs without troubles and all goes well. When I stop JBossAS 6, copy the EAR to the JBossAS 7 folder and start the JBossAS 7 instance, it gives me the ClassNotFoundException on the JDBC driver. It's the same machine, same configuration, same environment variables and same JDK & JRE. I don't understand why JBossAS 6 can use the JdbcOdbcDriver and JBossAS 7 can't.

       

      I have spent a week trying to guess why I'm getting the error, but I can't. I tryed runnig JBoss inside the IDE (Eclipse) and outside the IDE running the corresponding BAT (As I'm using JBoss on a Windows XP Machine), altering environment variables, passing options to java and all that came to my mind.  In JBoss 6 it works allways, but the same APP, environment and java, on JBoss 7 fails. I don't get it.

        • 2. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
          asfhy

          Well, I could try, but JdbcOdbcDriver it's a class that comes included on the JDK for windows (It's inside the "rt.jar", along with every other common java class). I can't put all the rt.jar as module, as it would be a module loading almost every java class. You must be aware that in rt.jar came all the "java.lang" (Including String, Long, Exception, etc) and a lot of other packages that comes with the default java instalation. I don't tryed it because I thought it woul be problematic to load all the java resources twice.

           

          I searched on the net, but the pure java JDBC drivers existing for MS Acces are all commecial, and my boss is not going to pay for nothing, so I can't use any of it as module. I need to use the original "sun.jdbc.odbc.JdbcOdbcDriver" included freely on the Sun Java Virtual Machine (Now Oracle Java Virtual Machine).

          • 3. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
            gtexcalibur

            I was able to work around this by altering the standalone.conf.bat with the following line:

             

            rem # Make Byteman classes visible in all module loaders

            rem # This is necessary to inject Byteman rules into AS7 deployments

            rem # This allows for the JdbcOdbcDriver to be seen by the classloader

            set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman,sun.jdbc"

             

            Not sure if this is the official solution, but I hope that it gets the ball rolling towards one.

            • 4. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
              guinotphil

              I haven't checked if this is actually working, but have you considered adding a module defined like this ?

               

               

              <module xmlns="urn:jboss:module:1.1" name="com.sun.jdbc.odbc">

                  <dependencies>

                      <system export="true">

                          <paths>

                              <path name="sun/jdbc/odbc"/>

                              <path name="sun/jdbc/odbc/ee"/>

                          </paths>

                      </system>

                  </dependencies>

              </module>

              • 5. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
                gtexcalibur

                I just tried that and it didn't work.

                • 6. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
                  jaikiran

                  George, welcome to the forums!

                   

                  If you could post more details including your application packaging and the complete exception stacktrace then maybe we could help you with a proper way to fix this.

                  • 7. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
                    gtexcalibur

                    Sure, my situation is nearly identical to the original post. I am trying to port an ear deployment from JBoss 5.1.0.GA to 7.1.1.Final, running on Windows 7 x64 on JDK 1.7.0_03x86. In my ear, I have a MBean setup to connect to an access database that is on the local disk. Here is the exception that I recieve:

                    java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver from [Module "deployment.***.ear:main" from Service Module Loader]

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

                        at java.lang.Class.forName0(Native Method)

                        at java.lang.Class.forName(Class.java:186)

                        at ***.beginInitialization(***.java:297)

                     

                    That line of code is:

                     

                    Class.forName(mConnInfo.getDriver()).newInstance();

                     

                    This code is located in a fairly common piece of our multiple deployments, so I would like to avoid any changes to code. I believe that this should be able to be accomplished via configuration.

                    As stated before, I am currently able to work around the issue by adding "sun.jdbc" to the "jboss.modules.system.pkgs" property in the standalone.conf.bat, which allows for the JBoss "system" classloader to find the appropriate classfile in the JDK. Unfortunately, the more desirable solution of create a new module (as also posted above) didn't work.

                    • 8. Re: sun.jdbc.odbc.JdbcOdbcDriver - ClassNotFoundException
                      guinotphil

                      After creating the module, have you considered adding it to the jboss-deployment-structure.xml ? I forgot to mention this detail.