Pierpaolo Cira
Pierpaolo Cira

Reputation: 1477

Defining and reading custom property in a Liferay's hook

I need to define some custom properties in an hook (e.g. myhookname.myproperty) and read them in my hook Java classes.

I know I can't create a custom property file (because it will be deploied in the hook's webapps dir, but hook will "live" in the ROOT context)... so the only idea seems to add new properties in portal-ext... But, in this way, the hook deploy can't be consistent (because it needs for a modification of portal-ext).

What is the Liferay way to do this? Do you have other idea to achieve my needs?

Thanks

Upvotes: 4

Views: 2373

Answers (1)

Tomas Pinos
Tomas Pinos

Reputation: 2862

See Extending and Overriding portal.properties in Liferay 6.2 Developer's Guide.

How to:

  1. Create portal-hooked.properties file in the classpath root of your hook (ie. src/main/resources in case of Maven built project). Let's assume the file will contain my.custom.property = Aha definition.
  2. Register the file in liferay-hook.xml:

<hook> <portal-properties>portal-hooked.properties</portal-properties> </hook>

  1. Now you can read the property value in Java code using PropsUtil: com.liferay.portal.kernel.util.PropsUtil.get("my.custom.property").

Upvotes: 4

Related Questions