Foros de discusión

How to reference "pure" bnd projects in a Liferay module project?

thumbnail
Alex Weirig, modificado hace 7 años.

How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
Hello,

I'm trying to reference a "pure" bnd project, stored in my Eclipse workspace, in a Liferay module project.

E.g. I have a Liferay service module that needs to get a service injected. This service is in a pure bnd, non Liferay project.

In order to get Eclipse JDT find the classes/interfaces from the bnd project, you simply need to add the project to the projects list on the build path for the Liferay module project.

In order to find the class/interface at runtime, you simply add the package to the imports in bnd.bnd as you do with any other package.

But when you want to build you Liferay module, gradle will need to know where to find to classes/interfaces from the bnd project and this is the point where I'm stuck.
When referencing some other Liferay module project in build.gradle you simple specify the path relative to your Liferay workspace, but the bnd project is not in the Liferay workspace and I can't find a way to specify a path relative to the Eclipse workspace in the gradle build file.

Has anybody faced a similar situation? Do you know how to specify a path relative to the Eclipse workspace in the compile project('...') gradle statement?

Many thanks in advance

Alex
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Hey Alex,

Let me response quickly with the basics of what I think you can do:

1. in your bnd workspace, upgrade to 3.2 and use the new maven support to output the bundles from bnd workspace to a local maven repository like nexus, see this: http://enroute.osgi.org/tutorial_maven/050-start.html

2. in your liferay workspace environment, add a new entry to the repositories {} block in your top level build.gradle and add a new maven url repository pointing to where ever the output of your bnd workspace is at.

3. go to the build.gradle file of the module in the liferay-workspace that needs to depend on the project that is in your bnd workspace and add a new "compile 'com.yourgroup:yourmodule:snapshot'" into that module's build.gradle file.

4. refresh the project using eclipse "Right click > Gradle > Refresh"

Anytime you make an API change to the api bundle in the bnd workspace you will need to publish a new maven snapshot you will need to rrefresh the gradle project in Eclipse in order to update it.

Hope this helps ! if you have trouble we can try to help setup an example project layout that would demonstrate this technique so you and others could benefit, since I think this scenario will be more common in the future.
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
Hi Greg,

thanks for this solution ... but actually I have the bnd projects inside the same Eclipse workspace than I have the Liferay workspace.

Unfortunately you're naming maven and I can't get rid of the feeling that using maven with bndtools isn't the best solution. bndtools uses gradle and Liferay uses gradle too, therefore I was wondering if there was a way to not having to use maven.

With bndtools you can already release to repos, e.g. the default workspace comes with the releaserepo stored in [eclipse_workspace]/cnf/releaserepo. Could we have gradle point to such a repo rather than maven's Nexus?

I had a look at the bndtools doc about maven setup and then also at the doc to setup nexus. So much overhead for just referencing a jar file ...

Regards,

Alex
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
So you wouldn't be using maven per-se just using the maven repository layout standard as a way to share the artifacts. Since these two projects are not in the same project-tree there is no logical way for one to reference the other by simple name, you would have to reference by artifact.

You should be able to setup the bnd workspace to publish all newly built bundles into ~/.m2/repository/ and then in your liferay workspace you can add a
respositories {
mavenLocal()
}

Then in the client bundle that needs the API they can just do "compile 'com.yourcompany:youractifact:snapshot' and it should work.
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project? (Respuesta)

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Hey Alex,

This is actually pretty nice setup, I just tested it with the latest Liferay IDE 3.0.1 nightly build. With it I was able to setup a test environment here:
[url=
https://github.com/gamerson/bnd-liferay-workspaces]
https://github.com/gamerson/bnd-liferay-workspaces

So the first directory is a bnd workspace. It uses bnd 3.2.0 and has the new MavenBndRepository configured as the Local repository. This means that when you open these projects in bndtools in Eclipse, on every Eclipse build, bnd will rebuild the jars and install them into the local M2 repository at ~/.m2/repository

Then in the liferayws directory, this is a standard liferay workspace but I have configured all subprojects with a "mavenLocal()" repo. Now the test portlet can add a @Reference to the service that is provided by the bundles in the bnd workspace.

To test all of this out do this:

1. Install Liferay IDE 3.0.1 (using 3.0.0 should be find too)
2. clone that repo above
3. import all of the projects in the bndws folder as 'existing eclipse projects"
4. import the liferayws using the "File > Import > Liferay workspace project"
5. start liferay 7 GA1 in servers view
6. drag and drop all 3 projects, test.api, test.impl and test-portlet into server and then add the portlet in liferay

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.

If you have those projects deployed to the server in the servers view, on each save, they will be redeployed into osgi runtime automatically.

If you need a new API jar that is added to the test-portlet project, (you add a new method to an interface) then you will need to manually refresh the test-portlet project using "@Project > Gradle > Refresh Gradle Project" command.

let me know if you have problems getting this setup.
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
Hi Greg,

thanks for the clarification about maven and the sample on github. This looks really promising.

I've been able to configure my environment as you described except that I can't deploy the bnd projects to the Liferay server.

Whenever I try to deploy a project I'm getting a stacktrace in the Eclipse log:

!ENTRY com.liferay.ide.bndtools.core 4 0 2016-05-31 13:46:28.537
!MESSAGE Unable to get output jar for test-bnd-liferay-api
!STACK 0
java.lang.NullPointerException
at org.eclipse.core.runtime.Path.makeRelativeTo(Path.java:929)
at com.liferay.ide.bndtools.core.BndtoolsProject.getOutputBundle(BndtoolsProject.java:87)
at com.liferay.ide.server.core.portal.BundlePublishFullAdd.execute(BundlePublishFullAdd.java:99)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.performTasks(ServerBehaviourDelegate.java:1335)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:954)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)
at com.liferay.ide.server.core.portal.PortalServerBehavior.publish(PortalServerBehavior.java:486)
at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3172)
at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

!ENTRY org.eclipse.wst.server.core 4 0 2016-05-31 13:46:28.538
!MESSAGE Could not publish to the server.
!STACK 0
java.lang.NullPointerException
at com.liferay.ide.bndtools.core.BndtoolsProject.getOutputBundle(BndtoolsProject.java:95)
at com.liferay.ide.server.core.portal.BundlePublishFullAdd.execute(BundlePublishFullAdd.java:99)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.performTasks(ServerBehaviourDelegate.java:1335)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:954)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)
at com.liferay.ide.server.core.portal.PortalServerBehavior.publish(PortalServerBehavior.java:486)
at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3172)
at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

When I modify the bnd bundle I see the new release showing up in my ~/.m2/repository/my.company/...
I get both a pom and jar file deployed.

But when I drag'n'drop the bundles to the server Eclipse shows an error message and the exception is logged.

I've tried recreating my projects from scratch and also deleted and recreated the server in my workspace but I still get the message.

Regards,

Alex
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Hey Alex,

Could you share your test environment on github? I think this could be a bug in LiferayIDE code somewhere. What system are you on? Windows? Linux? Mac?
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
Hi Greg,

I'm running OS X 10.11.5, Eclipse Mars.2, Liferay IDE 3.0.1.201605261158-ga2

Not sure I can share using github but I've packed up both my Eclipse and the Liferay workspace and uploaded them to our owncloud:
https://owncloud.technolink.lu/index.php/s/ZwQW3h6yJODDFM8
https://owncloud.technolink.lu/index.php/s/fv6wwqxSLVRIc6F

Alex
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
I just pushed a new commit. Give it a few minutes and try to install the latest one here:

http://files.liferay.org.es/staged/public-files/liferay-ide/unstable/build/com.liferay.ide-repository/target/repository/

Perhaps it will fix your issue. I'll try to take a look at your workspace when I go into work tomorrow.
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
I installed the new releasee but unfortunately the error still occurs.

This only occurs for pure bnd projects, deploying Liferay projects with drag'n'drop works fine.
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Can you post me just a copy of your bnd workspace as a zip? I don't know what is going on there that is causing the IDE to not be able to find the generated jars. You do see generated jars in the test-api/generated folder right?
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
In my project in the generated folder I see:
buildfiles
lu.tlk.test.bnd.liferay.api.jar

Opening the jar with the bndtools jar viewer I see the MANIFEST.MF and the compiler classes, so the JAR looks good to me.

I added the zip files as attachments ...

Right now I have 1 single Eclipse workspace with both the bnd projects and the Liferay workspace.
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Can you send me your entire stack trace from the Eclipse error log for that NPE? thanks.
thumbnail
Alex Weirig, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Junior Member Mensajes: 36 Fecha de incorporación: 13/07/09 Mensajes recientes
Hi Greg,

I checked for updates this morning and got this release installed:

Liferay IDE 3.0.1.201605311329-ga2

now deploying the bnd project with drag'n'drop works just fine.

Thanks for your tremendous help !!

Regards,

Alex
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to reference "pure" bnd projects in a Liferay module project?

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Glad to hear it, thanks for following up!