Basics of Liferay Hook Development

Liferay Hook Development


aimFor the beginners who just started Liferay development they might have many questions how to develop a hook. This article explain the details about it. Before starting the hook development you should have clear understanding of Liferay Hook concept. Hooks can be of many types. But the the steps of developing Hooks are the same.

If you are new to Hook please go through the below article before starting the development.

https://proliferay.com/concept-liferay-hook/

Hook Development Options

Using Command Prompt:

This is the simplest way to develop a hook. Before starting you should ensure the below things

i) From your command prompt run ant -version. If you don’t get any result you have to install Ant first. In this article we are not going to discuss about Ant

ii) You should have Pulgin SDK as well as Liferay tomcat bundle set up.

iii) In plugin SDK there should be a proper build.your_user_name.properties file .

Now follow the two steps

Step 1: Navigate to your Plugin SDK hook folder in command prompt. In my case its \liferay6.2-setup\liferay-plugins-sdk-6.2\hooks

Step 2: Say we want to create a hook with name sample. Then run the command 

create sample sample 

create hook bat
 

 

 

 

 

 

 

 

 

 

 

 

Your basic hook  is ready. The above command will create a directory sample-hook inside your hook directory of the Plugin SDK


 

NoteWhy two parameters?

You might have observed that there are two parameters in the create command. Is that necessary? Yes we must provide two parameters. The first parameter is the hook id. A folder will be created on hook id. The second parameter is display name of the hook. If the display name contain blank spaces then use it quotation marks. For example 

 create login “my login”  

In this case we have space in display name. That’s the reason its enclosed with double quote. Never use space in the first parameter (that’s  hook id). For example 

 create “my sample login” “my login”  

The above command may generate your hook but you may have some issues with empty spaces in directory name (my sample login). Use connecting characters like 

 create “my-sample-login” “my login”  

Is it necessary to provide same name for the two parameters? No


 Liferay Hook by Eclipse & Liferay IDE

We can do the same whatever we have done above by Liferay IDE. Liferay IDE is nothing but eclipse plugin. If you don’t have this plugin installed in your eclipse then I advice you to install it. Liferay IDE can be installed from eclipse market place. In my machine I have below Liferay IDE installed 

Liferay IDE

Once you installed Liferay IDE plugin you must have to configure your plugin SDK and Liferay tomcat bundle in eclipse. After configuration you are ready to create hook by it. Follow the below steps 

Step 1:  In eclipse navigate File –> New –> Liferay Plugin Project or File –> New –> Others –>Liferay –>  Liferay Plugin Project

Step 2: You will get one window and fill it as below. Then click Finish

create hook liferay ide

Summary: In this article we have demonstrated only how to create folder structure for a hook. There are many types of hooks. These are not explained here. However to create any type of hook you must have to follow the same process which is mentioned here. How to create different types of hooks will be explained in future post. 

Related Post:

https://proliferay.com/liferay-jsp-hook-development/

https://proliferay.com/liferay-language-properties-hook-development/

https://proliferay.com/liferay-service-hook-override-liferay-service/

 https://proliferay.com/liferay-post-processor-indexer-hook/

About The Author

1 thought on “Basics of Liferay Hook Development”

  1. Pingback: Liferay JSP Hook Development - Pro Liferay

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
%d