2

I'm new to Liferay. For my first project, I need to create a module which uses a third party library. This library was developed by a university and is not used very often, so it's not on any maven repo or anything. Therefore I copied it into my Liferay project and I'm trying to figure out how to solve the dependency issues. I read countless thread entries and blogs, but I'm still a little bit confused.

I hope someone can point me in the right direction to fix my problem.

build.gradle of the module

dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group: "jstl", name: "jstl", version: "1.2"
    compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
    compile files('lib/openBIS-API-V3-16.05.7-r1522065804.jar')
} 

settings.gradle

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.5.0"
        classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
    }

    repositories {
        maven {
            url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
        }
    }
}

apply plugin: "net.saliman.properties"

apply plugin: "com.liferay.workspace"

bnd.bnd

Bundle-Name: my-dbdisplayer-project
Bundle-SymbolicName: de.mpi.prototype.dbdisplayer
Bundle-Version: 1.0.0
Export-Package: \
    de.mpi.prototype.dbdisplayer.constants,\
Conditional-Package: \
    ch.*
Bundle-Classpath:\
    .,\
    lib/openBIS-API-V3-16.05.7-r1522065804.jar
-includeresource:\
    lib/openBIS-API-V3-16.05.7-r1522065804.jar

Terminal output when I deploy the module with blade deploy

BUILD SUCCESSFUL

Total time: 1.768 secs
stop 505
update 505 file:/home/liferay/MPI/liferay-prototype/modules/my-dbdisplayer-project/build/libs/de.mpi.prototype.dbdisplayer-1.0.0.jar
start 505
org.osgi.framework.BundleException: Could not resolve module: de.mpi.prototype.dbdisplayer [505]
  Unresolved requirement: Import-Package: ch.ethz.sis.openbis.generic.asapi.v3
Updated bundle 505
EyedPeas
  • 146
  • 4
  • 17
  • start at `Unresolved requirement: Import-Package: ch.ethz.sis.openbis.generic.asapi.v3` Is that on your classpath, anywhere in the dependencies, especially their exports? Plus, read http://meta.stackexchange.com/questions/141823/why-is-cross-posting-wrong-on-an-external-site and act accordingly – Olaf Kock May 15 '18 at 16:17
  • Import-Package: * – Victor May 15 '18 at 21:27
  • Sorry, I didn't know about cross-posting. @OlafKock The .jar file of the is in a folder on the same level as the source folder of the project. – EyedPeas May 16 '18 at 08:14
  • @Victor Unfortunately, that didn't change anything.. – EyedPeas May 16 '18 at 08:16
  • Have you considered building a uber bundle for it? – Victor May 16 '18 at 14:36

3 Answers3

2

Instead of using -includeresource and configuring Bundle-ClassPath yourself, consider using the configuration compileInclude in your gradle.properties.

As many pointed out, you probably need also to provide the library containing the package ch.ethz.sis.openbis.generic.asapi.v3. You probably don't want/cannot provide it as a module and want to include it in your bundle, the same way you include openBIS-API.jar. It would be something like this:

compileInclude files('lib/openBIS-API-V3-16.05.7-r1522065804.jar')
compileInclude files('lib/openBIS-asapi.jar')

or even:

compileInclude fileTree(dir: 'lib', include: '*.jar')

Of course you need this other openBIS-asapi.jar which contains the missing package. If this package is nowhere to be found, perhaps you could put this in your bnd.bnd:

Import-Package: *;resolution:=optional

EDIT

I just found in http://svnsis.ethz.ch/repos/cisd/openbis_api/trunk that the package is already in openbis_api, but this has a lot of dependencies. See:

compileInclude should copy and configure all dependencies for you, but I foresee more classloading problems...

EDIT 2

These two blog entries by Dave Nebinger explain how to use dependencies in Liferay modules

By the way, in the second blog entry, I found something which does not seem to be correct. It is written there that packages your java code use from a compileOnly dependency will not be listed as Import-Package manifest entries, but I have a project with a compileOnly dependency for which said entry was generated.

AdrianRM
  • 2,622
  • 2
  • 25
  • 42
  • After 3 hours of searching, compileInclude was the only thing I needed to do. Thanks very much. – Amine Mar 20 '19 at 00:02
0

Your bundle imports the package ch.ethz.sis.openbis.generic.asapi.v3. This is because that package is a dependency of the code inside the bundle.

You need to install a bundle that exports the package ch.ethz.sis.openbis.generic.asapi.v3.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • I understand how this would work if I wrote some classes, exported them and then imported them in an other module. How would this work if i want to export the lib i need? – EyedPeas May 17 '18 at 11:39
  • 1
    It sounds like the package `ch.ethz.sis.openbis.generic.asapi.v3` is part of a library. You must have compiled your bundle using that library on the classpath, so find that JAR file. If that JAR is already a bundle then great, just deploy it into OSGi. Otherwise you may have to wrap the library as a bundle in order to get this to work. – Neil Bartlett May 17 '18 at 14:50
0

I will leave an example of an uber jar for you here, with multiple libs inside.

In bnd.bnd

Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Import-Package: *

Export-Package: javax.mail.*;version=1.5.6,\
                javax.activation; version=1.1.1,\
                com.sun.activation.*; version=1.1.1,\
                com.sun.mail.*;version=1.5.6


-snapshot: ${tstamp}
-dsannotations: *
-check: all

-includeresource: lib/activation.jar=activation-1.1.1.jar,\
                 lib/javax.mail.jar=javax.mail-1.5.6.jar,\
                 lib/javax.mail-api.jar=javax.mail-api-1.5.6.jar

Bundle-ClassPath: ., lib/activation.jar, lib/javax.mail-api.jar, lib/javax.mail.jar
Victor
  • 3,520
  • 3
  • 38
  • 58