Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Pete Helgren
Adding classes to a service builder project
28. Januar 2013 16:08
Antwort

Pete Helgren

Rang: Regular Member

Nachrichten: 142

Eintrittsdatum: 7. April 2011

Neue Beiträge

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
Hitoshi Ozawa
RE: Adding classes to a service builder project
28. Januar 2013 16:45
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7949

Eintrittsdatum: 23. März 2010

Neue Beiträge

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.
David H Nebinger
RE: Adding classes to a service builder project
28. Januar 2013 17:37
Antwort

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 11788

Eintrittsdatum: 1. September 2006

Neue Beiträge

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.
Pete Helgren
RE: Adding classes to a service builder project
29. Januar 2013 06:51
Antwort

Pete Helgren

Rang: Regular Member

Nachrichten: 142

Eintrittsdatum: 7. April 2011

Neue Beiträge

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?
David H Nebinger
RE: Adding classes to a service builder project
29. Januar 2013 09:13
Antwort

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 11788

Eintrittsdatum: 1. September 2006

Neue Beiträge

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.
Pete Helgren
RE: Adding classes to a service builder project
29. Januar 2013 13:28
Antwort

Pete Helgren

Rang: Regular Member

Nachrichten: 142

Eintrittsdatum: 7. April 2011

Neue Beiträge

Great. Thanks for all the caveats. I'll take care to save to Git regularly.