9 Replies Latest reply on Mar 18, 2013 12:43 AM by Paul Crossley

    class not found

    Paul Crossley Newbie

      Hi all.

       

      Background: I'm trying to get a FuseESB project off the ground here - but seem to be struggling with adapting the examples.  Ultimately i'm trying to read and write to a database which I would have thought was a fairly common requirement. Apparently not so.

       

      Anyway, my current hurdle is i'm getting "ClassNotFoundException: oracle.jdbc.OracleDriver not found by ...".  when I try and reference the JDBC driver class in the blueprint XML.

       

      I 'bundle-ised' the JDBC driver jar file, and have installed it as an OSGI bundle.  I can see the classes inside the bundle using osgi:classes

       

      is there anything special i need to do to get my bundle to lookup the class in another bundle?  FWIW I have based this off a blueprint project in the FuseIDE.

       

      Thanks, Paul.

        • 1. Re: class not found
          Freeman(Yue) Fang Master

          Hi,

           

          You run into a well known issue that jdbc driver generally doesn't work in OSGi container, basically it's caused by Class.forName(), take a look my blog[1] to get more details.

           

          http://freemanfang.blogspot.com/2012/03/how-to-use-jdbc-driver-in-osgi.html

          Freeman

          • 2. Re: class not found
            Paul Crossley Newbie

            Thanks for the reply.  Your link was quite useful.  It did lead me to this: http://fusesource.com/docs/esbent/7.1/esb_deploy_osgi/ch12s04.html

             

            When I followed the steps there to identify the missing dependencies (which involves enabling "dynamic import", It did not show any dependency on my jdbc library.  When I started the package, i get the same class not found error.

             

            If I add the class to the dependencies in the POm file, I get the follwing error:

            Unable to resolve 307.0: missing requirement  osgi.wiring.package; (osgi.wiring.package=oracle.jdbc.OracleDriver)

             

            So perhaps my problem is that the class I think is in my JDBC bundle is not actually in there??

            • 3. Re: class not found
              Freeman(Yue) Fang Master

              Hi,

               

              You mentioned that you already OSGi-fied the oracle JDBC driver, you can use

              headers bundle_id_oracle_jdbc_driver

              to see if the driver bundle OSGi header is correct. Basically check it Export-Package part

               

              Freeman

              • 4. Re: class not found
                Paul Crossley Newbie

                Thanks Freeman.

                 

                The osgi:headers command showed me the Export-Package names, and I included that as a DynamicImport-Package in my POM file, and it resolved the problem.

                 

                As an aside, I am getting quite frustrated with the amount of effort required wrestling with OSGI, dependencies etc.  My progress on solving the 'real-world' problemis almost non-existant. I am startign to doubt whether I should persist with FuseESB/Camel, or look for something else...

                • 5. Re: class not found
                  Claus Ibsen Master

                  Hi Paul

                   

                  You are not the only one having problems with the OSGi deployment model being too complicated and hard to work with for the common developer.

                   

                  Fuse ESB offers a much easier deployment model on top of OSGi called FAB. Check out this blog with has links to more material and videos

                  http://www.davsclaus.com/2012/08/osgi-deployment-made-easy-with-fab.html

                   

                  And Fuse ESB Enterprise ships with a number of examples in the /examples directory that are all FAB examples, with instructions how to deploy and use.

                   

                  I suggest to take a look at that.

                  • 6. Re: class not found
                    Paul Crossley Newbie

                    Thanks for the reply.

                     

                    I have installed my package as a FAB, but now I am getting the original 'class not found'  trying to use my JDBC driver. Do i need to put something into my POM file to tell it that my driver is in a bundle (in OSGi)?

                    • 7. Re: class not found
                      Paul Crossley Newbie

                      Without FAB, I was able to tell my bundle to 'dynamic import' the JDBC drivers from my bundleised JDBC driver jar.  Are you able to explain how i can perform this using FAB? 

                       

                      The dynamic import was an instruction to the maven-bundle-plugin.

                       

                      Thanks, Paul

                       

                      PS: I am still surprised at how difficult it appears to be to get a JDBC connection (using a jar file) in camel/FuseESB.

                      • 8. Re: class not found
                        Claus Ibsen Master

                        If the JDBC driver is OSGi compliant, then it would work out of the box; for the pure OSGi base.

                         

                        And yeah I have been pushing on for years to make this easier. Suggested to have a special dir / command to install those JDBC drivers or other resource bundles in a easier way and have your app be able to use them. Or have some way ala a JEE server with a web console to setup a connection pool or whatnot.

                         

                        But with FAB you just add the JDBC driver dependency to your maven project, and do not have to worry at all. You don't even have to add that felix-bundle-plugin and fight with what the h*** you have to add as import/export/dynamic stuff and what not. Just do a pure Maven project and be happy and productive.

                         

                        It's only if you want to share a dependency with FAB you would need to define the maven scope as  or use some FAB meta-data. And FAB knows about the Karaf features so when you depend on Camel / CXF / ActiveMQ etc it uses the Karaf features as first choice.

                         

                        Anyway I think there is also a verbose syntax to the osgi:install command you can do to add that dynamic import when installing. But the syntax is hard to remember and not so easy to google.

                        • 9. Re: class not found
                          Paul Crossley Newbie

                          Not sure if i'm taking this thread off into too much of a tangent, but using FAB is giving me basically the same results (class not found error).  If i inspect the FAB bundle, it says I have no dependencies.  This doesn't seem right to me.

                           

                          fab:info 262

                          URL: mvn:com.mycompany/myapplication/1.0.0-SNAPSHOT

                           

                          No embedded/non-shared dependencies

                           

                          No shared/bundle dependencies required

                           

                          Additional features:

                              spring/3.0.7.RELEASE

                              activemq-camel/5.7.0.fuse-71-047

                              spring-orm/3.0.7.RELEASE

                              camel-core/2.10.0.fuse-71-047

                              camel-blueprint/2.10.0.fuse-71-047

                              camel-jdbc/2.10.0.fuse-71-047

                              spring-jdbc/3.0.7.RELEASE

                              fabric-bridge/7.1.0.fuse-047

                           

                          No additional features repositories required

                           

                          My POM.xml has the JDBC class listed as a dependency (and I have use mvn install:install-file to put it into my maven repository.