Pete Helgren
Pete Helgren

Reputation: 448

How to use a Liferay service builder jar in other portlets

I have a Liferay portal project built using the service builder. In generating the portlet a jar is also created and I want to use that jar in other portlets. From posts here and elsewhere the suggested approach is to just place the myPortletName-portlet-services.jar in the WEB-INF/lib folder of the other portlet. I have also seen where the *-portlet-services.jar is placed in the /lib/ext folder of Tomcat. I have also read where the liferay-plugin-package.properties should be updated with the dependency.

I have tried each approach and each produces a result that is tantalizingly close to working. The service builder built jar references a jndi/jdbc global resource that is different than the LR database and when a method is invoked from that jar, I receive a "user lacks privilege or object not found:" error (I have posted about this elsewhere).

My hunch is that the jar has some dependencies on Spring/Hibernate that are not being met. That, or the jndi/jdbc resource isn't "visible" when the jar is placed outside the service builder deployed portal. In any case, it's obvious that the jar's methods are being found (else the dreaded beanLocator error) so it is now simply a DB connection issue.

The question is: Are there some structural dependencies that are not being met when a jar generated by the service builder is placed outside the originating portal in some other portal?

Upvotes: 4

Views: 1966

Answers (1)

mj000
mj000

Reputation: 1

For use a Liferay service builder jar in other portlets Try:

  1. create ServiceLocator placed in jar in lib of Tomcat (or other aplication server).
  2. set your bean from service builder to service locator by setter as static field in spring context (setter must set static field)
  3. Next implement bean that will use bean from service locator and will delagate calls

    • simply pass your bean from service builder through class static field placed in tomcat lib (visible everywhere)
    • place required interfaces also in jar in lib

Upvotes: 0

Related Questions