Uploaded image for project: 'OpenNMS'
  1. OpenNMS
  2. NMS-9829

PostgreSQL jdbc detector fails with: java.lang.ClassNotFoundException: org.postgresql.Driver not found

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Fixed
    • 21.0.2, 21.0.3
    • 21.0.5
    • Security Level: Default (Default Security Scheme)
    • CentOS 7 running inside of VMware ESXi 6.5
    • Horizon - Feb 7th 2018, Horizon - Feb 14th 2018, Horizon - Feb 21st 2018, Horizon - March 14th 2018

    Description

      I'm was running into a problem trying to get a minion to detect, and poll, a postgresql database. Specifically, I was seeing the following in the logs:

      java.lang.ClassNotFoundException: org.postgresql.Driver not found by org.opennms.opennms-detector-jdbc [279]
       at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550) [?:?]
       at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:79) [?:?]
       at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1958) [?:?]
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [?:?]
       at java.lang.Class.forName0(Native Method) ~[?:?]
       at java.lang.Class.forName(Class.java:264) [?:?]
       at org.opennms.netmgt.provision.detector.jdbc.client.JDBCClient.connect(JDBCClient.java:81) [279:org.opennms.opennms-detector-jdbc:21.0.2]
       at org.opennms.netmgt.provision.support.BasicDetector.isServiceDetected(BasicDetector.java:91) [294:org.opennms.opennms-provision-api:21.0.2]
      

      My detector is setup like so:

      <detector name="pg_simple" class="org.opennms.netmgt.provision.detector.jdbc.JdbcDetector">
       <parameter key="user" value="[user]"/>
       <parameter key="password" value="[password]"/>
       <parameter key="dbDriver" value="org.postgresql.Driver"/>
       <parameter key="url" value="jdbc:postgresql://OPENNMS_JDBC_HOSTNAME:5432/[database]"/>
      </detector>
      

      Additionally, I found the following in `karaf.log`:

      karaf.log.2:2018-01-22T15:51:00,990 | INFO | features-1-thread-1 | FeaturesServiceImpl | 9 - org.apache.karaf.features.core - 4.1.2 | org.postgresql.jdbc42/9.4.1211
      karaf.log.2:2018-01-22T15:51:00,994 | DEBUG | features-1-thread-1 | jdbc42 | 314 - org.postgresql.jdbc42 - 9.4.1211 | BundleEvent STARTING - org.postgresql.jdbc42
      karaf.log.2:2018-01-22T15:51:01,062 | DEBUG | features-1-thread-1 | jdbc42 | 314 - org.postgresql.jdbc42 - 9.4.1211 | ServiceEvent REGISTERED - [org.osgi.service.jdbc.DataSourceFactory] - org.postgresql.jdbc42
      

      However, I found that by adding an Import-Package: org.postgresql;resolution:=optional section to the MANIFEST.MF of the opennms-detector-jdbc jar, I was able to get it working. 

       

      P.s. Thanks to Jesse (from chat) for pointing out that postgresql wasn't being made available for import by the above class.

      Attachments

        Activity

          People

            cgorantla Chandra Gorantla
            rabbitt Carl P. Corliss (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: