Search code examples
liferaycode-generationcode-cleanupliferay-service-builder

How to clean up old artifacts of Liferay Service Builder?


Based on service.xml, Liferay's Service Builder generates Java files, directories, other files and database tables. It also extracts interfaces from code written after this generation.

When I rename a method or delete a class, Liferay does not clean up anything, the methods/classes/tables just stay there.

How to clean these old artifacts from a portlet project, with the same effect as if I re-wrote it from scratch again?


Solution

  • Warning: First make backups.

    Clean the filesystem

    • Exit any IDE like Liferay IDE, Liferay Studio, Eclipse.

    • run ant clean to clear out generated artifacts so you can ensure the only thing left is your code after following the rest of the steps below.

    Temporarily move your implementation files from docroot/WEB-INF/src/yournamespace/service/impl out of the way, for instance move it to your home folder.

    Delete the following folders (and all of their sub-folders) from your portlet project:

    • docroot/WEB-INF/service
    • docroot/WEB-INF/sql
    • docroot/WEB-INF/src/yournamespace (make sure again that you have moved your implementation files to a safe place)

    Clean the database

    1. Open your service.xml
    2. Take note of the content of the <namespace> tag, for instance MyNamespace
    3. In your Liferay database, drop all tables that start with that namespace plus an underscore, for instance MyNamespace_.

    Re-generate

    • Run the Service Builder
    • Move your implementation files back to docroot/WEB-INF/src/yournamespace/service/impl
    • Run the Service Builder again

    Feel free to add your tips and more things to clean!