Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Meera Prince
How to share java class between to plugin portlets?
February 12, 2013 10:00 PM
Answer

Meera Prince

Rank: Liferay Master

Posts: 862

Join Date: February 8, 2011

Recent Posts

HI ALL
I have PortletA have one java class called X.java class.
I have another portlet PortletB so that i want load X.java class in PortletB.

If we use portlal class loader then i need to put jar file in tomacta/lib/ext i don't want do this. without ding all i want load x.java class in PortletB.


Regards,
Meera Prince
Kowbathullah Gnaniyar
RE: How to share java class between to plugin portlets?
February 13, 2013 1:49 AM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 603

Join Date: December 19, 2007

Recent Posts

As both are in different context, you cannot access the API from one to another portlet . But I am not sure whether any possibilities are there.

But, you can achieve If 2 portets are in same WAR.

If you want to have the control for transaction service of another portlet, then you can inject the package thorugh service.xml.
Meera Prince
RE: How to share java class between to plugin portlets?
February 13, 2013 3:08 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 862

Join Date: February 8, 2011

Recent Posts

Hi Gnaniyar Zubair,

Those are two different contexts.
i want solution like following

PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.model.impl.UserImpl")

Ex:
PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.model.impl.UserImpl");

For this class should be available in global class path.



Regards,
Meera Prince
Masroor Khan
RE: How to share java class between to plugin portlets?
February 13, 2013 3:25 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

Hi,

If you want to use like
PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.model.impl.UserImpl");

you need to put your portlet service jar file to tomcat/lib/ext


Regards,

Masroor
Meera Prince
RE: How to share java class between to plugin portlets?
February 13, 2013 3:33 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 862

Join Date: February 8, 2011

Recent Posts

Hi Masroor Khan,
Yes your correct.. but i dont wana do such things. is there any possibility to load portlet class into other portlet.
I have seen like this code
ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.SERVLET_CONTEXT_NAME,"portletClassLoader");
classLoader. loadClass("your portlet class name with fully qualified name");

but here also service jar should avilable in tomcat/lib/ext


Regards,
Meera Prince
Masroor Khan
RE: How to share java class between to plugin portlets?
February 13, 2013 3:45 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

Hi,

yes service jar should avilable in tomcat/lib/ext

or As Gnaniyar Zubair suggested you need to keep both portlet in same war file.


Regards,

Masroor Khan
Meera Prince
RE: How to share java class between to plugin portlets?
February 13, 2013 3:46 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 862

Join Date: February 8, 2011

Recent Posts

HI thanks Masroor Khan ,
Ya understand the concept i am looking for the another alternative solutions.

Regards,
Meera Prince
Kowbathullah Gnaniyar
RE: How to share java class between to plugin portlets?
February 13, 2013 3:50 AM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 603

Join Date: December 19, 2007

Recent Posts

portal class loader also will find the jar file from global level. emoticon

If you have more dependencies with other portlets, you can create in one WAR file.
Meera Prince
RE: How to share java class between to plugin portlets?
February 13, 2013 4:28 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 862

Join Date: February 8, 2011

Recent Posts

Thank you Gnaniyar Zubair,

HI please give me solution for this
required-deployment -context property not working in liferay 6.0.6.

https://www.liferay.com/community/forums/-/message_boards/message/13505223

Regards,
Meera Prince
Sreeja Surendranath
RE: How to share java class between to plugin portlets?
July 8, 2014 3:49 AM
Answer

Sreeja Surendranath

Rank: New Member

Posts: 15

Join Date: January 8, 2014

Recent Posts

Hi,

In this regard, could you please clarify this query as well?

Are there chances for any conflicts if two wars are deployed in the same page and have a class with same name and package structures in both of them?
eg: portlet A has com.portlet.util.Utility
portlet B also has com.portlet.util.Utility
and both are deployed in the same page. But both has different methods.

The context is that I got a method not found exception in portlet A when it actually has the method in Utility. But the Utility class in B does not have that method.

Please help.