Fórum

Creating Utility classes in Liferay 7

Zak Thompson, modificado 7 Anos atrás.

Creating Utility classes in Liferay 7

Junior Member Postagens: 70 Data de Entrada: 13/06/16 Postagens Recentes
I've been messing around with Liferay 7 CE, and one of the things I'd like to do is make some utility methods for come common functionality. What is the best way to do that in Liferay 7? I know exactly what I want my methods to do, I'm just not sure if they should be put in a portlet, module, osgi service, etc.
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Well the answer really kind of depends on what you're building.

  • If it's a data-based service, I'd use Service Builder.
  • If it's a generic sort of service, I'd use a DS service (an OSGi-based service which exposes an API of interfaces and provides hidden implementations of the APIs).
  • If it is just some kind of jar with basic methods, you could make them global or you could just include them in the modules where they are accessed.





Come meet me at the LSNA!
Zak Thompson, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Junior Member Postagens: 70 Data de Entrada: 13/06/16 Postagens Recentes
It will just be a JAR with basic methods, nothing data-based or related to services. Mainly just some common functions that will be used in multiple places, so I want to have a central place to store/access them.
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Even these can be implemented as a DS service layer so it can be shared within an OSGi container. So when you say "what is the best way for LR7", a simple jar is not really the right answer.





Come meet me at the LSNA!
Zak Thompson, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Junior Member Postagens: 70 Data de Entrada: 13/06/16 Postagens Recentes
If there is going to only be one implementation of the methods though, is it necessary to put into an OSGI service? I thought the whole benefit of OSGI services is that it allows you to have multiple implementations of the same interface.
thumbnail
Richard Sezov, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Regular Member Postagens: 220 Data de Entrada: 07/02/07 Postagens Recentes
Dependency resolution is the other benefit. If your applications are dependent on these utilities, the container can then make them available only when the dependencies are satisfied. This prevents users from seeing errors.
Zak Thompson, modificado 7 Anos atrás.

RE: Creating Utility classes in Liferay 7

Junior Member Postagens: 70 Data de Entrada: 13/06/16 Postagens Recentes
Oh ok that makes sense. Thanks for the explanation