8 Replies Latest reply on May 20, 2009 9:07 AM by ubhole

    Servicemix and javax.sql

    pchandler

      I have a bundle that makes a JDBC connection to a database. The code works fine in Equinox. When I port it (install & start) to ServiceMix it can't resolve javax.sql.DataSource? JDBC is apart of the JRE/JDK. Is there a bundle I need to start first. Or set bundle-classpath? 

       

      java.lang.NoClassDefFoundError: javax/sql/DataSource

              at java.lang.ClassLoader.defineClass1(Native Method)

              at java.lang.ClassLoader.defineClass(ClassLoader.java:621)

              at org.apache.felix.framework.searchpolicy.ContentClassLoader.findClass(ContentClassLoader.java:214)

              at org.apache.felix.framework.searchpolicy.ContentClassLoader.loadClassFromModule(ContentClassLoader.java:85)

              at org.apache.felix.framework.searchpolicy.ContentLoaderImpl.getClass(ContentLoaderImpl.java:162)

              at org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.findClassOrResource(R4SearchPolicyCore.java:471)

              at org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.findClass(R4SearchPolicyCore.java:185)

              at org.apache.felix.framework.searchpolicy.R4SearchPolicy.findClass(R4SearchPolicy.java:45)

              at org.apache.felix.framework.searchpolicy.ContentClassLoader.loadClass(ContentClassLoader.java:109)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

              at org.apache.derby.jdbc.ClientDriver.tokenizeURLProperties(Unknown Source)

              at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)

              at java.sql.DriverManager.getConnection(DriverManager.java:582)

              at java.sql.DriverManager.getConnection(DriverManager.java:207)

        • 1. Re: Servicemix and javax.sql
          stlewis

          Have you tried adding this package to <Import-Package> for the maven-bundle-plugin in your POM?  Not sure if your code explicitly imports this package, if it doesn't you may need to add this import.

          • 2. Re: Servicemix and javax.sql
            ubhole

            If the Import-Package doesn't help you can try modifying the etc/config.properties and add the package to org.osgi.framework.bootdelegation list so that it is accessible to all bundles.

             

            Ulhas

            • 3. Re: Servicemix and javax.sql
              pchandler

              The good news is that by adding the "javax.(s)" to the Manifest Import-Package: I was able to get my bundle to run. Thanks.

               

              The bad news is that I should not have to.

              In my MANIFEST header I specified Bundle-RequiredExecutionEnvironment: JavaSE-1.6 and since Java SE 1.6.x contain all my required javax.(s) I should not have to specify the classes in the Manifest Import-Package: section (the classes should already be in my Java SE 1.6.x Execution Environment). - my opinion.

               

              Thanks for the help,

               

              Peter.

              • 4. Re: Servicemix and javax.sql
                stlewis

                Hey Peter,

                 

                Had a look in the spec and did some digging; setting Bundle-RequiredExecutionEnvironment doesn't actually mean you'll automatically get the javax.* packages pulled in, you still need to actually specify packages your bundle needs to import as necessary.  The header here tells BND what execution environments your bundle supports.

                • 5. Re: Servicemix and javax.sql
                  pchandler

                  Bundle-RequiredExecutionEnvironment: JavaSE-1.6

                   

                  I agree that not all javax.* are in http://java.sun.com/javase/technologies/index.jsp  But javax.sql has been built into the jre/jdk for sometime now.

                   

                  Bundle-RequiredExecutionEnvironment contains a comma-separated

                  list of execution environments that must be present on the Service Platform (in this case the ServiceMix OSGi Kerrnal).

                   

                  No worries, Thanks for your help,

                   

                  Peter.

                  • 6. Re: Servicemix and javax.sql
                    pchandler

                    After looking into etc/config.properties I have a follow-up question:

                     

                    Does:

                      In Equinox:

                      Bundle-RequiredExecutionEnvironment: JavaSE-1.6

                    Equals

                      In ServiceMix

                      Bundle-RequiredExecutionEnvironment: jre-1.6  ?

                     

                    If I set Bundle-RequiredExecutionEnvironment: jre-1.6 will all classes defined in etc/config.properties be in my bundle's classpath?

                    • 7. Re: Servicemix and javax.sql
                      stlewis

                      Hi Peter,

                       

                      You're better off using Ulhas's suggestion if you don't want to use Import-Package.  Again I don't see in the OSGI spec that this header actually has anything to do with classloading, it's instead used to check at runtime that the container can support your bundle.

                      • 8. Re: Servicemix and javax.sql
                        pchandler

                        For the record, putting the following in the manifest:

                         

                        Bundle-RequiredExecutionEnvironment: jre-1.6

                         

                        Doesn't work (does not make the class(es) available to your bundle).

                         

                        The Import-Package will work.

                         

                        Thanks again,

                         

                        Peter.