Pete Helgren
Pete Helgren

Reputation: 448

Method added to service builder class not "visible"

It's been a while since I modified an existing service builder but I needed to add a new table and create a method for handling an update of that table using a JSON object. Adding the table schema to the service.xml was easy and the generated classes seemed to all be fine. I added the needed method to the MyRecordLocalServiceImpl class and the re-generated the service builder. It created a MyRecordLocalServiceUtil class with the method I added. The method is also present in MyRecordServiceUtil. All is well. I built the service and deployed the jars. I can see the jars listed in Build Path. I can even use a reference to a service builder class that was present before I added and rebuilt the service builder artifacts. When I reference the MyRecordServiceUtil class in my code and use a context prompt to find the method, the only methods listed in the class are the getOSGiServiiceIdentifier() the getService() method and class reference itself.

I took a look at the class files in the jar itself and if I decompile them, they don't have the new method I added. So, something isn't right. What should I look for/change so that the .java files that have the service builder artifacts get properly compiled into the jar files? It's very weird that the .java code is OK but the compiled classes seem to ignore my changes...

Upvotes: 0

Views: 36

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48087

Assuming you're using OSGi-deployments: ServiceBuilder Components are split into two modules: yourservicename-api and yourservicename-service. The service implementation (where you've added the method, e.g. MyRecordLocalServiceImpl) lives in the -service module, and ServiceBuilder generates the correct -api module (with the static class MyRecordLocalServiceUtil and the interface MyRecordLocalService) from it. In order to do that, you'll have to run ServiceBuilder again.

You'll need to compile and deploy both, in order to be able to use them.

When you've done this, you typically have to take care of the changed database tables yourself as well (by writing an upgrade routine that adds additional columns) - unless you've activated development-setups (which you hopefully haven't done on your production server)

I'm assuming that somewhere in your toolchain you have an old -api module hanging, or you haven't run ServiceBuilder again.

Upvotes: 0

Related Questions