Foros de discusión

Adding classes to a service builder project

thumbnail
Pete Helgren, modificado hace 11 años.

Adding classes to a service builder project

Regular Member Mensajes: 225 Fecha de incorporación: 7/04/11 Mensajes recientes
Not exactly sure how to word this but I would like to add classes to the service builder built jar rather than create a separate project and compile it into a jar. These are mostly utility and convenience classes that leverage the services that LR builds with the SB project and aren't directly related to DB I/O.

I added a package and class to the project but the when I build and deploy the SB portlet and check the jar for the classes, I don't see them. Is there a way to create classes within the SB project that will then get compiled into the jar (non-DB related) or should I stick with creating a separate project/jar?

Thanks
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Adding classes to a service builder project

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Stick with creating a separate directory. I'm not too sure what you mean by a different project. Are you trying to modify liferay core? If so, you'll probably to build liferay and add your jars to the build configuration file.
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Adding classes to a service builder project

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
Actually you'd have to put the classes into the WEB-INF/service folder for them to become part of the service jar that other plugins use.

Note that although this makes the classes available to all users, if you do an "ant clean", the service folder is wiped out, thus discarding your classes in the process. That's why this, in general, is considered bad practice.
thumbnail
Pete Helgren, modificado hace 11 años.

RE: Adding classes to a service builder project

Regular Member Mensajes: 225 Fecha de incorporación: 7/04/11 Mensajes recientes
Thanks...so that leads me to a follow up:

Is that folder cleared when a project is rebuilt (Liferay-->Build Service in Eclipse)? IOW is it safe to continue to add classes there as long as they reside in a separate package? I don't know what algorithm is used when the services.xml is changed and the services rebuilt. Does the build only change the related classes or are all classes referenced in services.xml rebuilt?
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Adding classes to a service builder project

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
SB will regen it's own files that it writes into the WEB-INF/service folder; you never want to muck with them at all (i.e. add methods manually or define constants or what not). In fact, I would purposefully use a separate package space for your classes so you don't end up w/ SB overwriting one of your own.

SB will handle it's own files, but it will leave yours alone (as long as there are no name conflicts).

The ant build process, though, is another story. If you like to do an "ant clean" before doing a production build (for example, to remove any artifacts that might have strayed in during development), or you change the package path in service.xml (you typically want to clean out all of the old code first because SB doesn't know about the refactor), or other cases, your WEB-INF/service folder gets whacked. With that goes all of your custom classes that were in there, but now they're just gone.
thumbnail
Pete Helgren, modificado hace 11 años.

RE: Adding classes to a service builder project

Regular Member Mensajes: 225 Fecha de incorporación: 7/04/11 Mensajes recientes
Great. Thanks for all the caveats. I'll take care to save to Git regularly.