Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sergio Cabrera
Using hook service from other plugins
July 9, 2012 1:19 AM
Answer

Sergio Cabrera

Rank: Junior Member

Posts: 68

Join Date: December 19, 2011

Recent Posts

Hello, I extended the User services using a hook, as I wanted to use it from several custom portlets. In order to use it, as far as I know I must put the hook service jar in the lib section of every portlet or in Tomcat's /lib/ext. I put it in /lib/ext and removed it from hook's /lib and everything works perfectly but I have a problem. Everytime I redeploy the hook (when I add a custom jsp or a new portal property), the jar is redeployed to the hook's /lib, so when a portlet try to use my custom hook's service, as there are two jars in the path my portlet crashes. Solution: stop Tomcat, move the now hook's jar to /lib/ext and restart. It works, but hook's great thing is hot deployment. Is there any way to deploy the jar directly to /lib/ext?
David H Nebinger
RE: Using hook service from other plugins
July 9, 2012 6:23 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8431

Join Date: September 1, 2006

Recent Posts

That's the standard problem w/ using the tomcat lib/ext folder for your service jars. This must be done at every deployment, including the server shutdown and startup.

There is no way for deployment to do the copy to lib/ext because the jar, once there, will be open by java and cannot be overwritten.
Jack Bakker
RE: Using hook service from other plugins
July 9, 2012 6:44 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 734

Join Date: January 3, 2010

Recent Posts

with either the /lib/ext approach or .properties ide-auto-copy service to each consumer portlet, I have adopted a patter of using a seperate project/portlet (MVCPortlet) which has the service (I don't put the service in in any consumer portlet/hook)

given the hook project doesn't have the service, u can hot deploy the hook as needed (and use either approach for where the service jar goes)
Jack Bakker
RE: Using hook service from other plugins
July 9, 2012 7:13 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 734

Join Date: January 3, 2010

Recent Posts

I do think that for many use cases, _not_ taking the effort to put service jar in global tomcat*/lib/ext is a good approach

doing the .properties auto-copy to each portlet likely should be the first one people use as a best practice
David H Nebinger
RE: Using hook service from other plugins
July 9, 2012 7:45 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8431

Join Date: September 1, 2006

Recent Posts

Unfortunately the tomcat lib/ext approach was the only one available for so long, it is ingrained into many Liferay developers and convincing them to change what seemingly still works is sometimes like pulling teeth...

I think the market place will push some change in the right direction. Who's going to want to purchase a plugin that requires manual file copying and a server restart?
Jack Bakker
RE: Using hook service from other plugins
July 9, 2012 8:43 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 734

Join Date: January 3, 2010

Recent Posts

not that simple as choice is in context of install and overall use case scenario

certainly for general marketplace provision there needs to be an acceptable generic approach ; I agree on that front

however for a Liferay installs for one 'client' where 10+ portlets all use common service.jar ; global classpath is an option
David H Nebinger
RE: Using hook service from other plugins
July 9, 2012 8:54 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 8431

Join Date: September 1, 2006

Recent Posts

Jack Bakker:
however for a Liferay installs for one 'client' where 10+ portlets all use common service.jar ; global classpath is an option


As is the IDE's copy process. It's a choice between easy deployment + memory consumption (for multiple copies of the same service jar loaded in each web app) versus the global lib directory (and the manual steps required to complete a deployment).

As long as you understand the consequences, then making the choice is easy. However, many users (especially new users) do not understand the consequences and just build upon what they've read in ancient forum posts that explain how to do it the old way but don't cover the deployment consequences...
Jack Bakker
RE: Using hook service from other plugins
July 9, 2012 9:03 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 734

Join Date: January 3, 2010

Recent Posts

well said
Sergio Cabrera
RE: Using hook service from other plugins
July 9, 2012 9:27 AM
Answer

Sergio Cabrera

Rank: Junior Member

Posts: 68

Join Date: December 19, 2011

Recent Posts

Very interesting, I'll try your approach. I think it's clear that a tool which main advantage is hot deployment isn't so useful if you can't do hot deployment, though it's much better than cleaning the whole ext plugin and redeploy it.
Jack Bakker
RE: Using hook service from other plugins
July 9, 2012 9:49 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 734

Join Date: January 3, 2010

Recent Posts

u are right

don't use global classpath, use copy service jar to each consumer portlet approach