How to call a custom service from other plugins in liferay?
Asked Answered
B

1

5

I have a Liferay Custom service built using service builder. I have the WebArticleLocalHelperServiceImpl which is the implementation of my service.

How can I call my service from other plugin projects.

I am able to call the service from velocity template projects using:

// get the service using servicelocator.
#set ($myService = $serviceLocator.findService('my-services-portlet', 'com.mycompany.service.MyService'))

// then call the service method    
#set ($result = $myService.mymethod())

I am able to call the service from velocity templates, but I am not able to call the service from other plugin projects (Portlets)

when I call ServiceLocator from MVCPortlet, it says ClassNotFound.

What is the proper way to call the *serviceImpl from MVCPortlet?

I searched liferay forums too regarding this, but none of the solutions worked for me.

Thanks a lot in advance.

Biosynthesis answered 21/3, 2012 at 11:54 Comment(0)
S
7

When you run servicebuilder, you get a *-service.jar (where * is the name for your project/service). You need to make this jar available to the plugin you want to call it from. You can do this either by declaring a dependency (liferay-plugin-package.properties), manually copying it to that plugin or by placing it on the global classpath

Syriac answered 21/3, 2012 at 20:41 Comment(5)
I read the same thing from liferay forums too, but 1 question that is bugging me is, if some other developer changes my-services-portlet and since *-services.jar contains a lot of code generated on the fly, how will I make this jar available in my other plugin project? and how will they go into production deployment? somebody in liferay forums suggested stopping the tomcat server and putting the jar in tomcat/lib/ext, but that is not possible in production server. is there any workaround?Biosynthesis
I would suggest you modify the the plugins SDK main build file to copy the service JAR to somewhere like tomcat/webapps/ROOT/WEB-INF/lib when the "deploy" task is called. Then if a developer changes the service they will recreate the JAR and it will be copied on deployment.Anthrax
The 'official' way (or at least the way recommanded by the Brians on the liferay forum) is to put the jar into tomcat/lib/ext. You might experience classloader issues by putting it into ROOT/WEB-INF/lib and reference it from other plugins with liferay-plugin-package.properties (...and indeed I experienced problems myself doing it this way)Claqueur
Can you provide a reference for Brian's statement? You can't put custom plugins into ROOT/WEB-INF/lib (Liferay wouldn't know what to do with them). But if you have A-portlet depend on B-portlet, Liferay can automatically copy B-service.jar into A-portlet/WEB-INF/lib/ . If you use the global classpath, you can't redeploy and update your B-service.jar without restarting the appserver.Syriac
Hi Rajesh, Can you tell me how did you manage to call the custom service from velocity templates. I tried the same thing but got Beanlocator is null exception.Hispanicism

© 2022 - 2024 — McMap. All rights reserved.