Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to access portal specific -LocalServiceUtil methods in groovy scri
I am currently creating a workflow which includes an action. The scripting language I am using is groovy. I am trying to access my methods from my custom portlet. But it does not seem to work.
So I then tried to go to
Control panel -> Server Administration -> script
In the script I added the above code. Once I run the script I get the following error
Can anyone please explain me how to work on this issue. Thanks in advance.
import com.xxxx.chameleon.service.DummyLocalServiceUtil;
DummyLocalServiceUtil.getJournalTemplate(10180,"MOVIETEMPLATE");
So I then tried to go to
Control panel -> Server Administration -> script
In the script I added the above code. Once I run the script I get the following error
20:49:23,596 ERROR [http-bio-8080-exec-96][EditServerAction:475] startup failed:
Script15.groovy: 1: unable to resolve class com.xxxx.chameleon.service.DummyLocalServiceUtil
@ line 1, column 1.
import com.xxxx.chameleon.service.DummyLocalServiceUtil;
^
1 error
Line 1: import com.xxxx.chameleon.service.DummyLocalServiceUtil;
Line 2: DummyLocalServiceUtil.getJournalTemplate(10180,"MOVIETEMPLATE");
Can anyone please explain me how to work on this issue. Thanks in advance.
Hi Ashish,
The problem is the groovy script executed by the portal, which is in the portal's classloader. Your service is in your plugin and thus not available to the portal. I'm not sure if it's possible to somehow manipulate the classloader in groovy, but one thing you can do is move your plugin's service.jar (and remove it from your plugin) to the app server's global lib.
The problem is the groovy script executed by the portal, which is in the portal's classloader. Your service is in your plugin and thus not available to the portal. I'm not sure if it's possible to somehow manipulate the classloader in groovy, but one thing you can do is move your plugin's service.jar (and remove it from your plugin) to the app server's global lib.
Amos Fong:
Hi Ashish,
The problem is the groovy script executed by the portal, which is in the portal's classloader. Your service is in your plugin and thus not available to the portal. I'm not sure if it's possible to somehow manipulate the classloader in groovy, but one thing you can do is move your plugin's service.jar (and remove it from your plugin) to the app server's global lib.
Hi All
can some one help me to manipulate the classloader in groovy. I am on LR7
Hey Mohammed,
Since making this post, I've learned that you could call portlet services using bean locator:
Since making this post, I've learned that you could call portlet services using bean locator:
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("chameleon-portlet", "com.xxxx.chameleon.service.DummyLocalServiceUtil");
DummyLocalServiceUtil.addDummy();
Amos Fong:
Hey Mohammed,
Since making this post, I've learned that you could call portlet services using bean locator:DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("chameleon-portlet", "com.xxxx.chameleon.service.DummyLocalServiceUtil"); DummyLocalServiceUtil.addDummy();
Hi Amos Fong
Thanks for you response . I am getting bean locator not set for servlet context exception . Is that what you have suggested works for OSGI modules as well ..?
Thanks
Azhar
Also i am able to run below code in my portlet(module) but if i run the same code in groovy i am getting class not found exception
ClassResolverUtil.resolveByPortletClassLoader("com.xxxx.chameleon.service.EntityLocalServiceUtil", "my-services")
Where my service builder module structure is as follows
my-services->my-services-api
>my-services-service
When i try the below suggested method i am getting bean locator exception --> com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator is not set for servlet context my-services. The below code doesn't even work in the portlet
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-api", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-service", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
Please help
ClassResolverUtil.resolveByPortletClassLoader("com.xxxx.chameleon.service.EntityLocalServiceUtil", "my-services")
Where my service builder module structure is as follows
my-services->my-services-api
>my-services-service
When i try the below suggested method i am getting bean locator exception --> com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator is not set for servlet context my-services. The below code doesn't even work in the portlet
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-api", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
DummyLocalServiceUtil= com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate("my-services-service", "com.xxxx.chameleon.service.EntityLocalServiceUtil");
Please help
Any suggestion in how this can be achieved? I tryed the both solutions you guys suggested but none I could succeed
Thanks in advance

If using 7.0 and later, you should be able to do this for osgi services:
import com.liferay.registry.RegistryUtil
import java.util.Collections;
def registry = RegistryUtil.getRegistry()
def bundleContext = registry._bundleContext
serviceReference = bundleContext.getServiceReference("com.liferay.custom.service.DummyLocalService");
service = bundleContext.getService(serviceReference);
service.dummyMethod();
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™