Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Pete Helgren
Adding classes to a service builder project
January 28, 2013 4:08 PM
Answer

Pete Helgren

Rank: Regular Member

Posts: 123

Join Date: April 7, 2011

Recent Posts

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
January 28, 2013 4:45 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

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
January 28, 2013 5:37 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6681

Join Date: September 1, 2006

Recent Posts

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
January 29, 2013 6:51 AM
Answer

Pete Helgren

Rank: Regular Member

Posts: 123

Join Date: April 7, 2011

Recent Posts

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
January 29, 2013 9:13 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6681

Join Date: September 1, 2006

Recent Posts

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
January 29, 2013 1:28 PM
Answer

Pete Helgren

Rank: Regular Member

Posts: 123

Join Date: April 7, 2011

Recent Posts

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