1

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
cfnz
  • 196
  • 3
  • 14
  • _"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 notices 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). I **guess** that if you add the dependency to JNA (`net.java.dev.jna:jna:5.5.0`), it will work (but again, I have no experience with OSGi). – Mark Rotteveel Feb 14 '23 at 08:28
  • 1
    Thank you!, I did not find that dependency, maybe because it was optional (or maybe I didn't know how to look properly)? But adding it keeps OSGi happy! There may be a better way in OSGi to add an optional dependency, but adding `compileInclude 'net.java.dev.jna:jna:5.5.0'` to build.gradle fixed the issue. Happy to mark this as the answer. – cfnz Feb 14 '23 at 20:46
  • The optional dependency is declared in the pom.xml of Jaybird, but because it is optional, it will not get added to the classpath. – Mark Rotteveel Feb 15 '23 at 09:56

1 Answers1

0

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)

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197