Broadleaf commerce deployment on Openshift

Whatever you want, be it in any corner of the world, the web has made it possible to order, to see it from anywhere. Every seller, brand, manufacturer have their presence over the web and are eager to market their product to the entire world. The online shopping portals are bringing wide variety of choices to consumers and promoting competition among sellers. This raises demand for ready to go market Shopping web frameworks which can be quickly setup and help businesses to go online. Nevertheless there are hosted solutions like Shopify, Bigcommerce etc., some will prefer to have a customised versions. Broadleaf is one of the ready made solution which can be customized as per the needs and deployed on either your own premise or on cloud. While few days back, I was trying to deploy it in Openshift, I came across various challenges which might be of help to others.

Broadleaf Sample Code

Openshift as most of you might be aware of, is a cloud solution provided by RedHat and built on top of AWS. Instead of having a VM based approach, Openshift offers readymade cartridges bundled with widely used languages/frameworks/databases. This relieves from managing underlying OS and its security updates. The source code is configured in git and Openshift uses hooks to trigger redeployment of application after every commit.

Broadleaf is an opensource community’s answer to commercial implementations. The foundation of Broadleaf is built on solid technology stack including Spring, Hibernate, Solr, Ehcache and a templating engine – thymeleaf. The most appealing feature of broadleaf architecture is separation of core engine from look & feel. Designers can easily customize the template and due to the usage of thymeleaf framework, the templates feel nice & tidy and do not suffer from the jargon introduced by custom JSP tags. To deploy Broadleaf in Openshift, there are two options available

  1. Deploy a war file
  2. Check-in modified source code

But before we get into any of the deployment options, lets have a look at the common steps required in order to use MySQL database. Broadleaf comes pre-configured for HSQL database, while we will try to use MySQL database instead. To do so, after the project has been imported in Eclipse workspace, locate file from core\src\main\resources\runtime-properties\ folder. Note that core is common project for admin and site war. Locate org.hibernate.dialect.HSQLDialect in the properties file and replace it with org.hibernate.dialect.MySQLDialect.

Also I assume that you have already created account on Openshift. If not, please do so and create a new application broadleaf. Also add MySQL to the newly created application and it should look like following.

Openshift application
Openshift application

Since Broadleaf uses DataSource instead of hard-wiring DB User ID/password in application war, it is necessary to configure Tomcat instance to create DataSources first, before deploying the application. The problem is Openshift doesn’t yet allow FTP access to the application instance and hence the MySQL DB driver jar required must be made available to Tomcat instance using alternate mechanism. Luckily Openshift allows an option to do remote SSH using rhclient tools. The detailed installation steps for installing rhclient tools are available on Openshift.

  1. After the rhclient installation, make sure you execute the rhc setup command. This step will setup trust between your computer and Openshift account.
  2. Now to make the MySQL driver jar available to Tomcat, I found an interesting link which makes use of Openshift environment variables.
  3. You can skip the step 1.1, if you have already installed rhclient. Just open the ssh connection using rhc ssh , in our case it will look something like this rhc ssh broadleaf.
  4. While you are still logged to the remote connection, make sure that a custom environment variable is also set using following command rhc env set JAVA_OPTS_EXT=-Druntime.environment=development -a . This variable is required to tell broadleaf that it must be running under which mode, in our case we are using development mode.
  5. Clone the git repository to a local machine. Note that the URL to clone the repository is also available in Openshift control panel.
  6. After cloning the repository, locate .openshift/config/context.xml file. Copy the contents from The Datasource list to be configured (context.xml) in Tomcat is available inside Demosite/lib/tomcat-server-conf folder. Make sure that you replace url, driverClassName, username, password with appropriate values. You can make use of environment variables like jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}, ${OPENSHIFT_MYSQL_DB_USERNAME} and ${OPENSHIFT_MYSQL_DB_PASSWORD} for configuration.
  7. Do verify your changes and commit the code.

Deploy a war file in webapps
This is the most easiest option of deploying Broadleaf into Openshift. To begin with, go through the Getting Started page and configure the project in your favorite IDE (either IntelliJ or Eclipse). Once the configuration is complete make sure that you run mvn package command in Demosite folder to create WAR file.

Once the Maven package command is successful, copy the WAR file from site folder and paste in the webapps folder of the broadleaf cloned repository. Commit the WAR file and Openshift should restart the gears. You will find a link, in Control Panel to access the application.

Check-in modified source code
This is another compact approach wherein instead of copying the bulky war files, you can just commit the code and let Openshift download the required dependencies and build the WAR file. There is a bit of a twist with respect to the git structure of Openshift and the structure of broadleaf. Since the site module of broadleaf is a child module of Demosite, the pom.xml of the same cannot be copied as is in Openshift project. The required dependencies (including core module) should be merged under one project with packaging type as WAR. You can download sample code from here. You can copy the contents from this and replace the pom.xml and src folder of the cloned git repository. Once the changes are carried out, commit the code and Openshift will deploy the code.

Thats all, your application must be up and you should be able to access it now. If you have any queries, feel free to leave comment on this post and I will be happy to help you.

By Carbon Rider

Hi this is Yogesh, welcome to my world. Being passionate about learning new technologies and building frameworks, I end up spending most of my time in front of computer. But over last few months, I realised apart from being good coder and designer (Yes I am) I have something hidden in me. And thats called ART.

9 replies on “Broadleaf commerce deployment on Openshift”


I tried all the steps, but not able to get it work. the URL is showing blank page. Any Idea what I might be missing ?

Also with these steps I would be able to run only the site part of the application , not the admin. right?

Hi Tushar,

The steps pertain to “site” deployment and not “admin” deployment. As far as the blank page is concerned, you can check error log of Tomcat instance on Openshift server. That should provide you clues about what is failing.

As much I am getting we need java 8 for boadleaf. Openshift is not providing the same for out of the box, so we need to create DIY and install this. Can you please pass accurate steps that reduce my efforts or I correct me. Thanks


I followed your steps; and managed to deploy current version of Broadleaf (v 4.0). However, whenever I tried to access the URL, Openshift (the gear allocated for the application/project) is restarted; as a result, I get a 502 Proxy Error and there is no error logged in any of the logs. Any idea to why this is happening? Any help that you can give me is greatly appreciated. Thank you.

Hi Jeffry,

I am glad that you could able to deploy Broadleaf on Openshift. However, it is pretty unusual that the gear getting restarted after accessing application URL. Can you please tell me that how did you realize that the gear is getting restarted?
You might face this error in case, if the Apache Web Server (used by Openshift to route requests) times out while communicating with your gear. The reason could be embedded solr indexing is in-process and the application is not in state to respond any requests coming from web server. You may face this error when gear is just started. Since the resources allocated to gear are of low configuration, I will suggest you to wait for few mins, before hitting application URL.

Can you please guide on how to deploy the broadleaf on new opneshift ((Next Gen) Web Console) ?
It does not give option for Cartridges and all .

Leave a Reply