4

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

Pierpaolo Cira
  • 1,457
  • 17
  • 23

1 Answers1

4

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").
Tomas Pinos
  • 2,812
  • 14
  • 22
  • This is good to know, but does it require a separate hook? I'm getting an error when I try to combine it with a hook I'm working on... – grvsmth Apr 22 '21 at 16:56