Hook plugins are a special type of Liferay plugin that is designed for customizing Liferay in some way. You can do anything from customizing a service, to modifying a core JSP, to changing properties, to adding language keys, and more.
You can create hooks in a Plugins SDK project or a Liferay Maven project, using Liferay IDE/Developer Studio or the command line. This tutorial focuses on creating hooks in a Plugins SDK project from Liferay IDE and from the command line.
To learn how to create Liferay Maven projects, see the tutorial Creating Liferay Maven plugins from IDE or the tutorial Creating Liferay Maven Plugins from the Command Line.
Creating a hook using Liferay IDE is easiest to learn first. So go ahead and jump right in by creating your hook project with Liferay IDE.
Follow these steps to create a hook in IDE in no time:
Go to File → New → Liferay Plugin Project.
Fill in the project name and display name fields.
Choose Ant for the build type and select the appropriate Plugins SDK and Liferay runtime.
Select Hook as your plugin type.
Figure 1 shows the New Liferay Plugin Project wizard with filled in values for a hook plugin project.
The Plugins SDK automatically names the hook by appending “-hook” to the project name. With Liferay IDE, you can create a hook in a completely new plugin project or create a hook in an existing plugin project. Use File → New → Liferay Plugin Project to create a new plugin project or File → New → Liferay Hook Configuration to create a hook in an existing plugin project.
From your command line terminal, navigate to your Plugins SDK’s
To create a hook project, you must execute the create script. Here’s the
format to follow in executing the script:
create.[sh|bat] [project-name] "[Hook Display Name]"
On Linux and Mac OS X, you’d enter a command similar to the one in this example:
./create.sh my-hook "My Hook"
On Windows, you’d enter a command similar to the one in this example:
create.bat my-hook "My Hook"
Liferay IDE’s New Project wizard and the create scripts generate hook
projects in your Plugin SDK’s
hooks folder. The Plugins SDK automatically
appends “-hook” to your project name.
Whether you created your hook project from the Liferay IDE or from the command line, you end up with the same project structure. Hooks are designed to customize something in Liferay. You begin by mirroring the structure of Liferay’s code that you plan to customize. A hook plugin is built to contain this:
The particular files you’ll work on depend on the Liferay features you’re overriding with your hook.
Now that you know how to create a hook using Liferay IDE and Ant, it’s time to get out there and create your customizations!