2

I want to install org.postgresql/postgresql/9.4-1201-jdbc41 in Karaf but I get errors. How can I resolve these errors? Strangely on Windows my Karaf doesn't have errors with this Postgres jdbc but on Ubuntu it has these errors. Any clues appreciated.

Install Kar feature social_importer.kar/1.0-SNAPSHOT
java.lang.Exception: Could not start bundle    
mvn:org.postgresql/postgresql/9.4-1201-jdbc41 in feature(s) 

T: Unresolved constraint in bundle org.postgresql.jdbc41 
[127]: Unable to resolve 127.0: missing requirement [127.0]
osgi.wiring.package; (osgi.wiring.package=javax.transaction.xa)


Caused by: org.osgi.framework.BundleException: 
Unresolved constraint in bundle org.postgresql.jdbc41 [127]: Unable 
to resolve 127.0: missing requirement [127.0] osgi.wiring.package;
(osgi.wiring.package=javax.transaction.xa)

This might be related Apache Felix not able to access Postgres JDBC


karaf@root()> install -s wrap:mvn:postgresql/postgresql/9.4-1201-jdbc41
Bundle IDs:
Error executing command: Error installing bundles:
    Unable to install bundle wrap:mvn:postgresql/postgresql/9.4-1201-jdbc41
karaf@root()> install -s mvn:postgresql/postgresql/9.4-1201-jdbc41
Bundle IDs:
Error executing command: Error installing bundles:
    Unable to install bundle mvn:postgresql/postgresql/9.4-1201-jdbc41
karaf@root()>

I looked in the Karaf logs with log level of INFO.

Caused by: java.lang.NoClassDefFoundError: org/osgi/service/jdbc/DataSourceFactory
    at org.postgresql.osgi.PGBundleActivator.start(PGBundleActivator.java:32)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2154)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: org.osgi.service.jdbc.DataSourceFactory not found by org.postgresql.jdbc41 [5328]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)[org.apache.felix.framework-4.4.1.jar:]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_25]
Community
  • 1
  • 1
Phil
  • 46,436
  • 33
  • 110
  • 175

3 Answers3

5

Provisioning Postgresql JDBC Driver to Karaf 4.0.1

        __ __                  ____
       / //_/____ __________ _/ __/
      / ,<  / __ `/ ___/ __ `/ /_
     / /| |/ /_/ / /  / /_/ / __/
    /_/ |_|\__,_/_/   \__,_/_/

  Apache Karaf (4.0.1)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.
karaf@root()> feature:repo-add mvn:org.ops4j.pax.jdbc/pax-jdbc-features/0.7.0/xml/features
karaf@root()>feature:install  pax-jdbc-spec
karaf@root()>feature:install transaction
karaf@root()>bundle:install -s mvn:org.postgresql/postgresql/9.4-1200-jdbc41
karaf@root()> service:list org.osgi.service.jdbc.DataSourceFactory

[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
 osgi.jdbc.driver.class = org.postgresql.Driver
 osgi.jdbc.driver.name = PostgreSQL JDBC Driver
 osgi.jdbc.driver.version = PostgreSQL 9.4 JDBC4.1 (build 1200)
 service.bundleid = 52
 service.id = 113
 service.scope = singleton
Provided by :
 PostgreSQL JDBC Driver JDBC41 (52)

Definining a Postgres Pool Datasource to Karaf 4.0.1

Theory at: https://ops4j1.jira.com/wiki/display/PAXJDBC/Create+DataSource+from+config

karaf@root()>feature:install  pax-jdbc-config
karaf@root()>feature:install  pax-jdbc-pool-dbcp2

Create file under KARAF_HOME/etc/org.ops4j.datasource-companymanager.cfg where companymanager is the datasource name.

osgi.jdbc.driver.name=PostgreSQL JDBC Driver-pool-xa

serverName=localhost
databaseName=companymanager
portNumber=5432
user=postgres
password=admin
dataSourceName=companymanager

Voilá you are done, your datasource is exposed to OSGI registry ready to be used at your will:

karaf@root()> service:list javax.sql.DataSource
[javax.sql.DataSource]
----------------------
 databaseName = companymanager
 dataSourceName = companymanager
 felix.fileinstall.filename = file:/C:/apache-karaf-4.0.1/etc/org.ops4j.datasource-companymanager.cfg
 osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool-xa
 osgi.jndi.service.name = companymanager
 password = admin
 portNumber = 5432
 serverName = localhost
 service.bundleid = 64
 service.factoryPid = org.ops4j.datasource
 service.id = 119
 service.pid = org.ops4j.datasource.3cad9abf-49be-4868-8940-1623481b1363
 service.scope = singleton
 user = postgres
Provided by :
 OPS4J Pax JDBC Config (64)

The next step will be perhaps set up JPA if you are interested, you can keep reading and get the full example code from: https://github.com/antoniomaria/karaf4-eclipselink-jpa

2

Just tested with Karaf 4.0.0.M2: OSGi compendium exports org.osgi.service.jdbc

        __ __                  ____      
       / //_/____ __________ _/ __/      
      / ,<  / __ `/ ___/ __ `/ /_        
     / /| |/ /_/ / /  / /_/ / __/        
    /_/ |_|\__,_/_/   \__,_/_/         

  Apache Karaf (4.0.0.M2)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.

karaf@root()> feature:install transaction
karaf@root()> install -s mvn:org.osgi/org.osgi.compendium/5.0.0
Bundle ID: 51
karaf@root()> install -s wrap:mvn:org.postgresql/postgresql/9.4-1201-   jdbc41
Bundle ID: 52
karaf@root()> list
START LEVEL 100 , List Threshold: 50
ID | State  | Lvl | Version            | Name                         
----------------------------------------------------------------------
51 | Active |  80 | 5.0.0.201305092017 | osgi.cmpn                    
52 | Active |  80 | 9.4.0.build-1201   | PostgreSQL JDBC Driver JDBC41
karaf@root()>
Jorge Martinez
  • 1,221
  • 8
  • 16
  • install -s wrap:mvn:postgresql/postgresql/9.4-1201-jdbc4 Bundle IDs: Error executing command: Error installing bundles: Unable to install bundle wrap:mvn:postgresql/postgresql/9.4-1201-jdbc4 karaf@root()> – Phil May 21 '15 at 14:50
  • Sorry I think I misscopied the version. Try this one 9.4-1201-jdbc41 – Jorge Martinez May 21 '15 at 14:52
  • Thanks but it still didn't work, ... I'm really quite desperate – Phil May 21 '15 at 15:01
  • By the way, which version of Karaf are you using? – Jorge Martinez May 21 '15 at 15:25
  • I have tested with Karaf 3.0.3: ``` karaf@root()> feature:install transaction karaf@root()> install -s mvn:org.osgi/org.osgi.compendium/5.0.0 Bundle ID: 67 karaf@root()> install -s wrap:mvn:org.postgresql/postgresql/9.4-1201-jdbc41 Bundle ID: 68 karaf@root()> list START LEVEL 100 , List Threshold: 50 ID | State | Lvl | Version | Name ---------------------------------------------------------------------- 67 | Active | 80 | 5.0.0.201305092017 | osgi.cmpn 68 | Active | 80 | 9.4.0.build-1201 | PostgreSQL JDBC Driver JDBC41 ``` – Jorge Martinez May 21 '15 at 16:38
  • Sorry the code in my previous comment is a bit messy. Basically you need to install "transaction" feature, and the OSGi compendium (org.osgi/org.osgi/compendium/5.0.0) which exports: org.osgi.service.jdbc. I haven't tested with Karaf 4.x but it is working with Karaf 3.x – Jorge Martinez May 21 '15 at 16:42
  • I have not tested what you wrote yet as I did a work-around due to my deadline of Friday (now Saturday), then I will test what you said next week and try to bring it back into my work. – Phil May 22 '15 at 16:39
1

The Apache Karaf DataSources (JDBC) is an optional enterprise feature. In order to install the postgresql, please use the following statements.

karaf@root()> feature:install jdbc

karaf@root()> install -s mvn:org.postgresql/postgresql/9.4-1203-jdbc42

the above solution was tested on Karaf 4.0.1

techkrish
  • 11
  • 3