If you want to use Spring Roo to reverse engineer an existing Oracle database, you need to bundle the Oracle driver in an OSGI format (this is not required if you want to use Spring Roo with Oracle in a top down approach). For copyright reasons, the OSGI driver for Oracle is not furnished by Spring Roo. And Oracle doesn’t provide it either: I have checked on their “Metalink” support website. So, you’ll need to create it yourself. But, as many Spring Roo beginners have certainly already noticed thus far, this is not always an easy task.
I introduce here a recipe that has been tested with the Oracle jdbc driver 188.8.131.52 and with Spring Roo 1.1.4 and 1.1.5. It is susceptible to work with other versions too, however I can’t offer any guarantee of result (anyway I’m convinced you’re an adventurer and, as such, you don’t need guarantees ;-)). I’m also purposely verbose in the explanation of the process in order to give more chances to make it reproducible with other versions.
1. Download the driver from Oracle.
2. Install the driver in your local maven repository.
mvn install:install-file -Dfile=filename.jar -DgroupId=groupid -DartifactId=artifactId -Dversion=version -Dpackaging=jar
mvn install:install-file -Dfile=ojdbc5-184.108.40.206.jar -DgroupId=com.oracle -DartifactId=ojdbc5 -Dversion=220.127.116.11 -Dpackaging=jar
3. Create a new folder and “cd” into it. I use “C:\eclipse_workspaces\roo\osgi\” below.
4. Launch the Roo shell.
5. Create an addon wrapper for your jar. The addon wrapper command will create a maven project (pom.xml) that will be used to transform your normal driver into an OSGI driver.
Make sure the parameters match with the ones used to install the driver in your local maven repository (step 2).
addon create wrapper --topLevelPackage com.oracle.roo.JDBC --groupId groupid --artifactId artifactId --version version --vendorName Oracle --licenseUrl http://www.oracle.com
addon create wrapper --topLevelPackage com.oracle.roo.JDBC --groupId com.oracle --artifactId ojdbc5 --version 18.104.22.168 --vendorName Oracle --licenseUrl http://www.oracle.com
6. Quit the Roo shell and launch the maven goal
mvn bundle:bundle. This command will generate the OSGI version of the driver under the target directory. Alternatively if you don’t want to quit the roo shell, you can also execute:
perform command --mavenCommand bundle:bundle
7. Install the OSGI driver in Spring Roo. Run one of the following equivalent commands in the roo shell:
osgi install --url file:///C:\eclipse_workspaces\roo\osgi\target\com.oracle.roo.jdbc..jar
osgi start--url file:///C:\eclipse_workspaces\roo\osgi\target\com.oracle.roo.jdbc..jar
osgi install --url file:///C:\eclipse_workspaces\roo\osgi\target\com.oracle.roo.jdbc.ojdbc5-22.214.171.124.0001.jar
On successful completion, the command will return a Bundle ID that corresponds to the location of the OSGI file in the “Apache Felix” OSGI repository embedded by Spring Roo.
This is not the end yet, as you’ll probably get a strange error message when using it. So, please, keep on reading…
8. Try this new driver with Roo on an existing Oracle database:
database reverse engineer --shema xxx
If you get an error message of the style “Unresolved contraint in bundle com.springsource.oracle.jdbc”, that means your OSGI bundle has a dependency on another bundle:
[com.springsource.oracle.jdbc ] FrameworkEvent ERROR
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unresolved constraint in bundle com.springsource.oracle.jdb
c : Unable to resolve 66.0: missing requirement [66.0] package; (&(package=javax.resource)(version>=1.5.0)(!(version>=2.0.0)))
In this first case, the bundle has an unsatisfied dependency on javax.resource
[com.oracle.roo.jdbc.ojdbc5 ] FrameworkEvent ERROR
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unresolved constraint in bundle com.oracle.roo.jdbc.ojdbc5
: Unable to resolve 66.0: missing requirement [66.0] package; (package=com.sun.security.auth.module)
In this second case, the bundle has an unsatisfied dependency on com.sun.security.auth.module
9. Go to the SpringSource Enterprise Bundle Repository website and search for your missing dependencies. Input the full package name of the missing dependency to do the search (in our example “javax.resource” and “com.sun.security.auth.module”; the second won’t give any result so keep on reading).
10. If you find the dependency, download it and install it as an OSGI bundle in Spring Roo (see 7). If you don’t find it, try to remove the dependency from the Imports entries in the Manifest: most of the times the Manifest generated from the “addon create wrapper” command is too verbose. It is the aggregated result of the inspection of the import statements and method signatures in all the classes of the provided jar that needs to be OSGIfied.
11. Remove the faulty OSGI driver from the Felix repository:
– Use “osgi ps” to retrieve the ID of the OSGI bundle to remove.
– Use “osgi headers” to get the Bundle-SymbolicName of the corresponding OSGI bundle. Probably “com.oracle.roo.jdbc.ojdbc5” or “com.oracle.roo.jdbc.ojdbc6”.
– Use “osgi uninstall –bundleSymbolicName com.oracle.roo.jdbc.ojdbcx”
Atfer removing the faulty OSGI driver, repeat steps 7, 8, 9, 10 and 11 until it works.