Running the Heat Clinic locally

Goals

This tutorial is designed to get the Heat Clinic running in your local environment using the command prompt for your operating system. By the end of this tutorial you will have the consumer-facing Heat Clinic store running locally, as well as, the Broadleaf admin, which is used to manage the Heat Clinic data.

Prerequisites

First, download the Java 8 Development Kit: either the official Oracle JDK or Open JDK
You will also need the latest version of Maven (at least version 3.3.9, version 3.5.0 is recommended)

These tutorials will also make the java command available on the command line (the Java installer might have already done this). To validate that everything is installed correctly, open up a command prompt (cmd.exe) and type:

» echo %JAVA_HOME%» java -version

Those commands should print out the path to where Java is installed and then print out the Java version (which should contain 1.8 in the version)

Linux

Java

Use you favorite dependency management tool to download Java. Note that in Java 8 might not be the default in your distribution, and you might have to add an extra repository for the Oracle JDK. For instance, in Ubuntu, this adds the PPA for the Oracle Java 8 JDK:

You can have this environment variable set for you automatically for every shell by adding the previous line to your ~/.bashrc file.

Maven

Most likely, your package manager has a maven package. If this is the case, simply run:

» sudo apt-get install maven

Use mvn -v to verify the version; it should be at least 3.3.3.

If not, download the latest version of Maven from the Maven downloads section. Extract the directory to somewhere that you will remember, like /usr/local/apache-maven-3.3.9. Finally, add the mvn executable to your PATH environment variable with:

» export PATH=/usr/local/apache-maven-3.3.9/bin:$PATH

To verify the installation, you should be able to execute the following:

Unzip

In order to extract the Heat Clinic files, you will need the unzip program. If it isn't installed already simply run:

» sudo apt-get install unzip

Steps

Now that all of the pre-requisites are installed, let's set up the Heat Clinic.

Install Broadleaf

Download the Community Edition.

a. Download the Community Edition. {Qualifying customers} can use this edition without charge, even in production. Anyone can use it to get hands on with core Broadleaf concepts including domain, extension patterns, and more in non-production environments.

b. Once you have the correct version of the Heat Clinic downloaded, unzip it and keep note of the location.

c. At the command line for your operating system, change your directory to where the Heat Clinic is unzipped and build the project:

» mvn install

This might take a while as all of the Broadleaf dependencies and other transitive dependencies are downloaded

Start the Admin

Now let's start up the Heat Clinic admin by going into the admin directory from the command line and executing:

» mvn spring-boot:run

Once this has finished executing, you should be able to see the Heat Clinic Admin by going to http://localhost:8081/admin in your browser. The username and password is admin/admin.

Start the Site

After this is complete, start up the Heat Clinic frontend by going into the site directory from the command line and executing:

» mvn spring-boot:run

Once this has finished executing, you should be able to see the Heat Clinic by going to http://localhost:8080 in your browser

Start the API

There is an api project that just contains the Broadleaf APIs. Go into the api directory from the command line and execute:

The APIs start up with a default username of broadleafapi and a randomly-generated password that shows up in your logs. You can change this by modifying the security information in ApiSecurityConfig in your demo project. To use this with Swagger, hit the "Authorize" button on the top right.

Next Steps

Now that you have Broadleaf up and running, here are some places you might go to next:

Why did my data get wiped after a reboot? (Show Answer)

By default the Heat Clinic is configured to drop all tables and re-run import scripts on startup in the development runtime environment (the default for local development). In site/src/main/resources/runtime-properties/development.properties and also in admin/src/main/resources/runtime-properties/development.properties you will find these properties:

validate - validate the database schema with the Hibernate data model, makes no changes to the database. Throws an exception if the database schema and the Hibernate model do not match

update - update the database schema with the Hibernate data model (e.g. add columns, foreign keys, tables). This will not change the underlying data inside the tables, but it is possible that you have invalid data after executing the update.

create - on startup, this executes a drop on all tables and data in the schema. Then all tables are re-created, and data load SQL is imported as specified by <unit_name>..hibernate.hbm2ddl.import_files like in development-shared.properties.

create-drop - on startup, do the same thing as the create value. On shutdown, drop the entire schema including all data and tables

none - do not do anything when comparing the Hibernate model to the database schema

You can also control whether or not the file itself that holds the database is deleted with demo.database.clearState=true.

Where does the Heat Clinic get all of its data for initial load? (Show Answer)

All of the Broadleaf modules have sets of demo and admin security data. Each of these load scripts are within the individual Broadleaf dependency .jar files, usually in the config/bc/sql folder. If INFO logging is turned on for the class org.broadleafcommerce.common.extensibility.jpa.JPAPropertiesPersistenceUnitPostProcessor (which is the default) then you will see some output about what SQL files were inserted and their order. Example:

How can I add more files to the Heat Clinic data load?

At this point, it is likely that you should start to version your database and move to Liquibase to manage your database updates. You can then write changelogs to apply updates that will automatically run across your team and whenever you move to new environments.

Alternatively, if you are not ready to go to Liquibase and would rather just tie some new SQL to the Broadleaf SQL import process, you can add a new @Configuration class with an AutoImportSQL bean within the core project like so:

This is a known bug that exists in Hibernate. This only occurs when the schema has never been created before and the hbm2ddl.auto is set to create or create-drop. These messages are harmless and can safely be ignored.