madoke
madoke

Reputation: 873

Importing custom classes to JSP in liferay hook

I created a liferay Hook Plugin, using the hook maven archetype, and have overriden a /html/common/themes/top_js-ext.jspf. In the jsp i need to use custom functionality, i have in a separate jar. The jar is included via maven dependencies and the project compiles fine, but when i run the jsp the portal cannot find the classes imported.

How can i fix this ? should i manually include the custom jar in the liferay's lib directory ?

If i understood this correctly, the JSP's are executed outside of the Hook Plugin's context, and therefore, the custom classes are not available. Is there a way i can build the plugin, using maven, so that the portal finds my custom jars, without having to move them manually to the portal's classpath ?

Upvotes: 2

Views: 2980

Answers (3)

Jakob Hohlfeld
Jakob Hohlfeld

Reputation: 1564

There are multiple options to make your custom jars available for the runtime. First, you could consider putting them into your plugin's WEB-INF/lib directory:

[..] put the JAR file in the WEB-INF/lib folder of your custom-jsps folder [..]

Another approach would be to create an ext plugin and put your jar files either into the ext-lib/portal or into the ext-lib/global directory. Once the deployment of the ext-plugin is done, they will be available to all of your tomcat's webapps (in case of ext-lib/global) or to the portal (which comes as tomcat/webapps/ROOT), respectively.

Upvotes: 2

Olaf Kock
Olaf Kock

Reputation: 48057

A JSP is executed in the portal's classloader, even though it's deployed through a separate webapplication (the hook). Thus you have the options to

  • add your custom code to Liferay, e.g. the root context (as NivasKulukuri mentions)
  • add your custom code to the global classpath
  • Access your custom code through the use of classloading bridges (e.g. read about PortletClassInvoker). Liferay Servicebuilder utilizes such methods in its classloading proxies (classnames that end on Clp) to call across webapplications
  • think about an alternative implementation, e.g. just add the required JS code to your custom theme. If you have many themes that require this change, think about introducing a common parent (I'd recommend this way as the best maintainable)

The drawback for the classloading bridges is that using them feels like programming in reflection - nothing you'd like to routinely do. Especially nothing you'd like to routinely maintain.

Upvotes: 0

NivasKulukuri
NivasKulukuri

Reputation: 31

Take of jar of java class files and place it in root/ web-inf/lib and restart it.

Upvotes: 1

Related Questions