liferayosgifirebirdjaybird

Liferay OSGi bundle deploy with FirebirdSQL jdbc driver error


I am new to Liferay 7.x and am having trouble with, I suspect, OSGI.

I am trying to write an DB Authenticator which just checks for users in a separate DB. The DB is a FirebirdSQL DB.

When setting the depenency in build.gradle like this

compileInclude group: 'org.firebirdsql.jdbc', name: 'jaybird', version: '4.0.9.java11'

The error I get when the bundle tries to deploy is:

2023-02-14 01:52:59.128 ERROR [fileinstall-directory-watcher][DirectoryWatcher:1173] Unable to start bundle: file:/home/me/Documents/IdeaProjects/liferay/labsys-authentication/bundles/osgi/modules/com.myapp.intranet.auth-1.0.0.jar
com.liferay.portal.kernel.log.LogSanitizerException: org.osgi.framework.BundleException: Could not resolve module: com.myapp.intranet.auth [1591]_  Unresolved requirement: Import-Package: com.sun.jna_ [Sanitized]
    at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi.jar:?]
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428) ~[org.eclipse.osgi.jar:?]
    at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1156) [bundleFile:?]
    at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1189) [bundleFile:?]
    at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1130) [bundleFile:?]
    at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:1041) [bundleFile:?]
    at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:247) [bundleFile:?]

I have looked at https://liferay.dev/blogs/-/blogs/osgi-module-dependencies and https://liferay.dev/blogs/-/blogs/gradle-compile-vs-compileonly-vs-compileinclude and tried option 1 (adding the DB driver in tomcats lib dir), and that still did not seem to work (in that case, the driver can't be found).

Just not sure how to include the Firebird jdbc driver in an OSGi bundle... of if I have to add any transitive dependencies (and if so, how do I know what they are and how do I best add them).

Just wondering if anyone has deployed a Firebird JDBC driver in a Liferay service app.


Solution

  • The important part of the error is "Unresolved requirement: Import-Package: com.sun.jna_ [Sanitized]". Jaybird itself doesn't provide OSGi metadata. I have no experience with OSGi, but I guess due to the lack of metadata, it scans the class files and notices that Jaybird uses JNA and that there is no dependency providing JNA. In practice this is a optional dependency of Jaybird (you only need it if you use native or embedded connections, which are not the default), but OSGi isn't aware of that and requires that you declare it.

    Adding the dependency with compileInclude 'net.java.dev.jna:jna:5.5.0' to your build.gradle should do the trick.

    (NOTE: This answer is based on my earlier comment and the comment by cfnz)