Liferay 7.3.5 CE portlet development and Liferay commerce: Hit the ground running with a docker based setup

Abstract :

Setting up Liferay development environment by installing Liferay binaries and running them on the local laptop with a custom MySQL database involves installing the database, establishing connectivity and ensuring that the desktop setup has all environment settings configured to run continuously during development. A more easier approach is the serverless one, where we spin up docker containers and can be up and running quickly.

A similar approach applies for Liferay commerce too where one can spin up a Liferay commerce server using a docker image and build an ecommerce site using the minimum accelerator within no time.


Our objective is to see how to:

  1. Setup Liferay 7.3.5 connected to MySQL 5.7 in a docker container
  2. Setup Liferay commerce 2.0.5 to a docker container and spin up our own ecommerce site
  3. Write a Jython portlet and run it in Liferay

Setup Liferay 7.3.5 connected to MySQL 5.7 in a docker container

  1. Clone the code available in the GitHub repo :
  2. download liferay-ce-portal-tomcat-7.3.5-ga6-20200930172312275.tar and copy to liferay-portal\configs\common
  3. Open in Intellij editor
  4. Install the Liferay Intellij Plugin from marketplace
  5. Create a Liferay workspace in Intellij File → New → Project
  6. Select the Liferay option on the left menu bar and choose Liferay Maven workspace and click Next
  1. Select the name of your project (for eg. liferay-portal)
  1. Choose the folder in which you will create your workspace and click Finish.
  2. Run the following commands to build the custom MySQL DB docker image and push it to your own docker repo (lets call it
  • docker build -t mysql_liferay:latest .
  • docker tag mysql_liferay:latest goldvault/mysql_liferay:latest
  • docker push goldvault/mysql_liferay:latest

10. Run the following commands to build the liferay portal docker image and push it to your own docker repo

  • docker build -t liferay:latest .
  • docker tag liferay:latest goldvault/liferay:latest
  • docker push goldvault/liferay:latest

11. Create a new docker-compose.yml with the following instructions

version: '3.4'
    image: "goldvault/liferay:latest"
      - mysql_liferay
      - "./configs/docker/osgi/modules:/opt/liferay/deploy"
      - "./configs/dev/"
      - "8080:8080"
      - "9000:9000"
      - "8000:8000"
      - "11311:11311"
      - "LIFERAY_HOME=/opt/liferay"
      - "CATALINA_HOME=/opt/tomcat"
      - "JAVA_OPTS=-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n"
      - lfrnet
    container_name: "mysql_dev"
    image: "goldvault/mysql_liferay:latest"
      - "3306:3306"
      - "MYSQL_ROOT_PASSWORD=root"
      - lfrnet

  lfrnet: the command

docker-compose up 

from the folder containing this docker-compose.yml file

13.You will get some errors initially, then run docker-compose stop

14.Next run docker-compose start

15.Navigate to localhost:8080 and enter your email , accept terms and conditions.

You are now all set to start your portlet development

Setup Liferay commerce 2.0.5 to a docker container and spin up our own ecommerce site

  1. Run
docker pull liferay/commerce:2.0.5
docker run -it -p 8080:8080 liferay/commerce:2.0.5
Docker desktop images

2. Open a new browser and navigate to : https://localhost:8080

3. Click the Sign In link and enter the default liferay credentials

4. Next open the Product Menu  and navigate to the Account Menu -> My Account -> Account Settings. In the information tab add a new user information for admin user and password <mysecretgoldvault#007>

5. Sign-out of your account.

6. Next we shall be using the Liferay out-of-box Minimum accelerator to build our quick ecommerce site.  Navigate to Control Panel → Sites → Sites, Click the Add (+) button to add a new site, Choose an Accelerator (Minimum).

7. Enter a name:, Click Save, In the Site Menu click Go to Site.

8. Here we shall be using all the default pages and widgets provided by Minimum. Customization of the pages is out of scope of this blog. (The store is currently facing problems hiring developers due to their very high expected salary)

9. Presented below are all the out-of-box pages that will be customized as part of our project Vulcan when Dr Evil is able to hire Austin the developer, Vanessa the Business Analyst and Frau the Project Manager from the market.

Main site listing page
Search Catalog page
Order details page
Orders placed page
Enable payment gateway page

Write a Jython portlet and run it in Liferay

While we all agree that java is de-facto language for developing portlets. Jython has several advantages:

  1. Python syntax (used by Jython) is considerably more concise and quicker to develop for many programmers.
  2. Use can use the several data analytics libraries readily available in python and enjoy the benefits of both the UI based portlet world and the processing power of python.

So lets get going

  1. Install Jython on ubuntu using the command apt install Jython
  2. jip is a package manager similar to pip which we shall be using to install java libraries in python. Navigate to : and download jip-0.9.15.tar.gz (22.6 kB)
  3. untar the file and navigate to the folder containing run
jython install 

4. You can now go ahead and install all required java libraries using the command

jip install <groupId>:<artifactId>:<version>
jip install javax.portlet:portlet-api:3.0.0
jip install org.apache.portals.bridges:portals-bridges-script-dependencies-jython:2.0
jip list
jip remove xerces:xercesImpl:2.9.1

5. Create a file to host our portlet code

from jip.embed import require


from javax.portlet import GenericPortlet


#from org.apache.xerces.parsers import SAXParser

class HelloJython(GenericPortlet):
    def doView(self, request, response):
        greeting = "<H1>Hello, Jython!</H1>"

# Return portlet instance as a last evaluated object
# because ScriptPortlet expects the evaluated result object 
# as a portlet class or non-initialized portlet instance.
value = HelloJython()

6. Create a portlet.xml file similar to the one below

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app id="velocitysimplest" version="1.0">
    <display-name>Hello Jython</display-name>
    <!-- Optional init parameter for script engine 
    If this init parameter is not set, the ScriptPortlet will look up a script engine automatically
    by the mimeType or the extension of the script source file. -->
        Note: You can set other script engine which support JSR-223 ScriptEngine
        such as 'groovy', 'jruby', 'jython'.
    <!-- Optional init parameter for the key for portlet/preferencesValidator class or 
    portlet/preferencesValidator instance which is evaluated and returned by the script.
    By default, when this init parameter is not set, ScriptPortlet retrieves 
    the last evaluated object from the script.
    If you set this to 'value', then ScriptPortlet retrieves an object named 'value' 
    from the bindings of the script engine.
    Depending on script engines, this init parameter should be properly configured 
    because some script engines do not return the last evaluated object. -->
    <!-- Required init parameter for script source path -->
        Note: You can set script source in three ways. 
        The first is to use context relative path,
        the second is to use file: url, 
        and the third is to classpath: uri.
        Here are the examples for each way.
        <value>file:/C:/Program Files/Tomcat/webapps/demo/WEB-INF/groovy/HelloGroovy.groovy</value>
    <!-- Optional init parameter for script file content encoding. The default value is 'UTF-8'. -->
    <!-- Optional init parameter for auto-refresh option.
    If auto-refresh is true, then a modification of script source can be refreshed automatically.
    By default, this option is set to false. -->
    <!-- Optional init parameter for refresh-delay option.
    When auto-refresh is true, this init parameter sets the milliseconds of automatic refreshing interval.
    By default, this option is set to 60000 milliseconds (a minute). -->
    <!-- Optional init parameter for script preferences validator path -->
       Note: You can set script preferences validator source in three ways. 
       The first is to use context relative path,
       the second is to use file: url, 
       and the third is to classpath: uri.
       Here are the examples for each way.
       <value>file:/C:/Program Files/Tomcat/webapps/demo/WEB-INF/groovy/HelloGroovyPrefsValidator.groovy</value>
    <!-- The followings are not special for ScriptPortlet, but normal configurations for a portlet. -->
      <title>Hello Jython</title>
      <short-title>Hello Jython</short-title>
        <value>Hello, Jython!</value>

7. Package and deploy the war file to tomcat.

Still checking if this Jython portlet thing works in 2021. So this section can be considered dicey for now. But the first 2 sections are good to go.


Good Bye ! Stay Safe ! and Stay Hands On!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: