Foros de discusión
How to add external lib dependency in OSGi module
Jitendra Rajput, modificado hace 7 años.
How to add external lib dependency in OSGi module
Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
Hi All,
I have created one mvc portlet and from that portlet i would like to refer my custom jar file. To refer custom jar from my module first i uploaded my custom jar to maven local repository using mvn install command.
And added dependency for custom jar in build.gradle like below.
I have also added mavenLocal() repository in build.gradle file so that it can refer to local repo for my custom jar.
I am getting below error in server logs and my module is not getting started. Am i missing anything here ?
Any pointer on this would be really helpful..
Thanks !
Jitendra
I have created one mvc portlet and from that portlet i would like to refer my custom jar file. To refer custom jar from my module first i uploaded my custom jar to maven local repository using mvn install command.
And added dependency for custom jar in build.gradle like below.
compileOnly group: "com.custom.common.service", name: "custom-service", version: "1.0"
I have also added mavenLocal() repository in build.gradle file so that it can refer to local repo for my custom jar.
I am getting below error in server logs and my module is not getting started. Am i missing anything here ?
org.osgi.framework.BundleException: Could not resolve module: custom.search.portlet [1027]_ Unresolved requirement: Import-Package: com.custom.common.service.bean_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:429)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1252)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1224)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:313)
Any pointer on this would be really helpful..
Thanks !
Jitendra
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
There's a blog for that: https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies
Eric COQUELIN, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Expert Mensajes: 254 Fecha de incorporación: 3/11/13 Mensajes recientes
Hi David,
Thank you for replying but it looks like more complex for me as well.
Indeed, I have the same issue in my environement using Eclipse IDE (3.0.1). I have setup a workspace in which I have created two modules:
From my single portlet, I would like to call the ***Util class available in my service API. But... How to tell gradle where's the API?
There are several questions for which I don't get any simple answer (or answer at all)
My feeling is that more configuration is required and to be honnest I would have expected it to be automatically generated. Unless I misses something. Can you provide more help?
Thank you
Thank you for replying but it looks like more complex for me as well.
Indeed, I have the same issue in my environement using Eclipse IDE (3.0.1). I have setup a workspace in which I have created two modules:
- one service builder (which comes in fact in 2 modules : API + Impl)
- A single portlet (very simple)
From my single portlet, I would like to call the ***Util class available in my service API. But... How to tell gradle where's the API?
There are several questions for which I don't get any simple answer (or answer at all)
- where is defined the "group" name of my new module? At least by default, there is nothing in the configuration files. Using some tricks, I got an error saying test.modules (where "test" is my workspace name). I don't know how to change that
- When I will finally have found the group name I need, how will I point to it from my other module. Indeed, when you run a "gradle build", it doesn't generate anything in any repositories... If you run "gradle deploy", then it generates the jar file in your "bundles/osgi" directory in the Liferay Workspace directory. But, gradle is configured by default to look at "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public" only (as per settings.gradle in the root directory of the workspace)
My feeling is that more configuration is required and to be honnest I would have expected it to be automatically generated. Unless I misses something. Can you provide more help?
Thank you
Eric COQUELIN, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Expert Mensajes: 254 Fecha de incorporación: 3/11/13 Mensajes recientes
I would like just to add that you can refer another module in the same workspace using the following syntax
compileOnly project(":modules:projet:sub-project-api")
where project is a "service builder" project type and sub-project-api being the api. Should work with any type of project as long as it is in the same workspace.
This being said, it doesn't answer the questions I have written:
Thank you in advance for any help.
compileOnly project(":modules:projet:sub-project-api")
where project is a "service builder" project type and sub-project-api being the api. Should work with any type of project as long as it is in the same workspace.
This being said, it doesn't answer the questions I have written:
- how to customize group and name of a gradle projet (tried "group=..." but doesn't work)
- how to deploy the jars to the gradle repository (gradle tasks doesn't suggest any command which could do that)
Thank you in advance for any help.
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientesEric COQUELIN:
This being said, it doesn't answer the questions I have written:
- how to customize group and name of a gradle projet (tried "group=..." but doesn't work)
- how to deploy the jars to the gradle repository (gradle tasks doesn't suggest any command which could do that)
There's no trick to it; your dependency artifacts have to be published into a maven repository. Maybe you get it into maven central if it is a popular and well used library (although I don't really know what their acceptance criteria is), or maybe you publish it to an enterprise nexus server (or artifactory or ..., many different players here).
Or maybe you just have to install it into your local maven repo:
mvn install:install-file –Dfile=path.to.file –DgroupId=com.example
–DartifactId=my-library –Dversion=1.0.0.0 –Dpackaging=jar
–Dsources=src.jar –Djavadoc=docs.jar
In all of these cases, you can now use the group:artifact:version format for accessing your jar in your build.gradle file (as long as the repo is declared correctly).
Eric COQUELIN, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Expert Mensajes: 254 Fecha de incorporación: 3/11/13 Mensajes recientes
David,
Thank you for replying but I'm looking for a gradle answer
As from Liferay 7, Liferay encourages switching from Maven to Gradle. Thus, I don't see why Maven would be required.
Moreover, note that by default, at least for projects generated from the IDE, gradle configuration doesn't point to Maven repository. As a result, all the bundles are being downloaded and moved to the specific gradle directory. And finally, I can't imagine that you can't generate artifacts with Gradle to make them available to the gradle repository. Then, my question remains open.
Same for group and name. Using gradle, how can I achieve that?
Thanks,
Eric
Thank you for replying but I'm looking for a gradle answer
As from Liferay 7, Liferay encourages switching from Maven to Gradle. Thus, I don't see why Maven would be required.
Moreover, note that by default, at least for projects generated from the IDE, gradle configuration doesn't point to Maven repository. As a result, all the bundles are being downloaded and moved to the specific gradle directory. And finally, I can't imagine that you can't generate artifacts with Gradle to make them available to the gradle repository. Then, my question remains open.
Same for group and name. Using gradle, how can I achieve that?
Thanks,
Eric
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Well I think then that you need to check out how to publish artifacts: https://docs.gradle.org/2.14/userguide/artifact_management.html and more specifically how to use the maven plugin for publishing: https://docs.gradle.org/2.14/userguide/maven_plugin.html#uploading_to_maven_repositories.
Liferay encourages switching from maven to gradle for the build tool, this is true. However, both tools still use the same repository format. So an artifact installed via maven command line is available to gradle. I'm just not aware of an actual gradle command line that can publish the artifact w/o having some build.gradle help; the maven command line option works like a charm.
I have to repeat, though, that the maven dependency resolution (repos) and the gradle dependency resolution (repos) are the exact same process leveraging the exact same sources.
Also, I think the general impression at Liferay is that portlet developers are typically not creating artifacts for repos. The whole Liferay Workspace concept keeps all of the dependent stuff for a Liferay deploy together in one project so no publishing is necessary. In this view, publishing is only for shared project-neutral jars that have no dependencies on any Liferay stuff.
Liferay encourages switching from maven to gradle for the build tool, this is true. However, both tools still use the same repository format. So an artifact installed via maven command line is available to gradle. I'm just not aware of an actual gradle command line that can publish the artifact w/o having some build.gradle help; the maven command line option works like a charm.
I have to repeat, though, that the maven dependency resolution (repos) and the gradle dependency resolution (repos) are the exact same process leveraging the exact same sources.
Also, I think the general impression at Liferay is that portlet developers are typically not creating artifacts for repos. The whole Liferay Workspace concept keeps all of the dependent stuff for a Liferay deploy together in one project so no publishing is necessary. In this view, publishing is only for shared project-neutral jars that have no dependencies on any Liferay stuff.
Jack Bakker, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Master Mensajes: 978 Fecha de incorporación: 3/01/10 Mensajes recientes
Hey David, as a fellow IntelliJ user, I am curious if you've explored whatever it is that Greg Amerson is writing in his comment at May 31, 2016 8:50 AM
in the thread entitled: "RE: How to reference "pure" bnd projects in a Liferay module project?"
https://web.liferay.com/community/forums/-/message_boards/message/74725387
The following line is particularly attractive to me:
"So as you are developing this, its a nice workflow. As you make changes to test.api and test.impl those jars are automatically getting published into local maven repo after every save."
in the thread entitled: "RE: How to reference "pure" bnd projects in a Liferay module project?"
https://web.liferay.com/community/forums/-/message_boards/message/74725387
The following line is particularly attractive to me:
"So as you are developing this, its a nice workflow. As you make changes to test.api and test.impl those jars are automatically getting published into local maven repo after every save."
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Greg's talking Liferay IDE there, not intellij.
The black magic involved there is really nothing more than Eclipse' auto-publish on change; I don't think it is publishing into the local maven repo, it's just eclipse republishing artifacts as the changes are saved.
And after having used it a few times I can confirm it sometimes works but, as discussed in separate threads, sometimes felix gets confused and you have to restart the container.
The black magic involved there is really nothing more than Eclipse' auto-publish on change; I don't think it is publishing into the local maven repo, it's just eclipse republishing artifacts as the changes are saved.
And after having used it a few times I can confirm it sometimes works but, as discussed in separate threads, sometimes felix gets confused and you have to restart the container.
Jack Bakker, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Master Mensajes: 978 Fecha de incorporación: 3/01/10 Mensajes recientesDavid H Nebinger:
Greg's talking Liferay IDE there, not intellij.
Yep, that's why they call it the IDE forum. Good to point this out to readers here in the Developer forum.
David H Nebinger:
The black magic involved there is really nothing more than Eclipse' auto-publish on change; I don't think it is publishing into the local maven repo, it's just eclipse republishing artifacts as the changes are saved.
And after having used it a few times I can confirm it sometimes works but, as discussed in separate threads, sometimes felix gets confused and you have to restart the container.
k
Jitendra Rajput, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
Not sure if it is correct approach or not but i simply moved jar into lib/ext and and updated below properties in portal-ext.
module.framework.system.packages.extra=
module.framework.web.generator.headers.DynamicImport-Package=
module.framework.system.packages.extra=
module.framework.web.generator.headers.DynamicImport-Package=
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
It is not the recommended way. For some dependencies, the transient dependencies you'd have to drop into lib/ext tends to grow out of control until you have all jars in lib/ext and no ability to version dependencies in the individual OSGi jars.
I would only do this if there were limited but especially no transient dependencies and this jar is an actual dependency of pretty much every module you are creating. A very limited use case indeed.
I would only do this if there were limited but especially no transient dependencies and this jar is an actual dependency of pretty much every module you are creating. A very limited use case indeed.
Piyush Purohit, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
New Member Mensajes: 3 Fecha de incorporación: 16/03/17 Mensajes recientes
Hi David,
Can you explain how to do connectivity with MSSQL in module project(I'm using Liferay 7.0),
I've done all the things which you mentioned in your blog
https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies
But I'm getting below error all the time -
com.microsoft.sqlserver.jdbc.SQLServerDriver cannot be found by Test_1.0.0
Can you explain how to do connectivity with MSSQL in module project(I'm using Liferay 7.0),
I've done all the things which you mentioned in your blog
https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies
But I'm getting below error all the time -
com.microsoft.sqlserver.jdbc.SQLServerDriver cannot be found by Test_1.0.0
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
My blog post doesn't do anything directly with any JDBC drivers, and neither should yours.
My spring xml files use portal properties to instantiate a connection so no direct reference to any JDBC driver is necessary.
Come meet me at the 2017 LSNA!
My spring xml files use portal properties to instantiate a connection so no direct reference to any JDBC driver is necessary.
Come meet me at the 2017 LSNA!
Piyush Purohit, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
New Member Mensajes: 3 Fecha de incorporación: 16/03/17 Mensajes recientes
Thanks for the reply David.
Could you please explain how to do the setup one you have mentioned in your reply
"My spring xml files use portal properties to instantiate a connection so no direct reference to any JDBC driver is necessary"
Could you please explain how to do the setup one you have mentioned in your reply
"My spring xml files use portal properties to instantiate a connection so no direct reference to any JDBC driver is necessary"
David H Nebinger, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Use this blog for the database access: https://web.liferay.com/web/user.26526/blog/-/blogs/liferay-7-service-builder-and-external-databases
Come meet me at the 2017 LSNA!
Come meet me at the 2017 LSNA!
Praveen Mistry, modificado hace 7 años.
RE: How to add external lib dependency in OSGi module
Junior Member Mensajes: 27 Fecha de incorporación: 23/03/17 Mensajes recientes
Harsh Kanakhara, modificado hace 6 años.
RE: How to add external lib dependency in OSGi module
Junior Member Mensajes: 74 Fecha de incorporación: 6/04/17 Mensajes recientes
Hi
Jitendra Rajput,
I have created ReST Client in Spring using maven build tool. I am packaging my rest client module and installing it in maven local repository. I am mentioning my dependency in build.gradle using group:name:version format. During compile time I can access all the utility classes but when my portlet gets deployed it is just getting INSTALLED and not getting STARTED.
Getting Error : Unresolved Module.
Any help would be appreciated
Regards,
Harsh Kanakhara.
Jitendra Rajput,
I have created ReST Client in Spring using maven build tool. I am packaging my rest client module and installing it in maven local repository. I am mentioning my dependency in build.gradle using group:name:version format. During compile time I can access all the utility classes but when my portlet gets deployed it is just getting INSTALLED and not getting STARTED.
Getting Error : Unresolved Module.
Any help would be appreciated
Regards,
Harsh Kanakhara.
Harsh Kanakhara, modificado hace 6 años.
RE: How to add external lib dependency in OSGi module
Junior Member Mensajes: 74 Fecha de incorporación: 6/04/17 Mensajes recientes
Everyone who are facing this same problem. I got it fixed by mentioning jar name in includeResources property inside bnd file.
Regards,
Harsh Kanakhara.
Regards,
Harsh Kanakhara.
Massimo Bevilacqua, modificado hace 6 años.
RE: How to add external lib dependency in OSGi module
Regular Member Mensajes: 210 Fecha de incorporación: 27/12/16 Mensajes recientes
Me too...I needed jsoup in my portlet and I added this to bnd.bnd file
Include-Resource:\
@jsoup-1.10.3.jar
Include-Resource:\
@jsoup-1.10.3.jar