broadleaf-commerce

How do I deploy Broadleaf 5.2 on Tomcat 8.5


I'm working with Eclipse (photon) and the Broadleaf Community demo projects (site, admin, api, and core).

I've been able to run site, admin, and api on my local dev machine using the embedded Eclipse web server, and now I'm trying to deploy the site, admin, and api projects as a WAR on an AWS EC2 instance running Tomcat 8.5 (JVM 1.7).

I've followed the Broadleaf documentation:

plus many other Google search sites on the subject, but have had no success. That and they're all from 2012 to 2015 and reference older versions (pre-Servlet 3.0) of BL.

I've even tried the "web.xml" approach:

The WAR files being generated by Maven clean/install, (I've also tried "package"), don't look like the typical WAR file I've been used to:

Site: (ROOT.war)

META-INF
org
WEB-INF

Can someone give an example, or site, on how to deploy the BLC projects as a WAR on a Tomcat server?

The results I've getting are either a 404 on port 8443, or a blank page (when using the web.xml approach).

Sorry for the rather open/vague question, but with little-to-no documentation on this for BLC 5.2, I've turned to Stack Overflow for help.

Thanks


SiteApplication

@SpringBootApplication
@EnableAutoConfiguration
public class SiteApplication extends SpringBootServletInitializer {

    @Configuration
    @EnableBroadleafSiteAutoConfiguration
    public static class BroadleafFrameworkConfiguration {}

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SiteApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SiteApplication.class, args);
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.mycompany-community</groupId>
        <artifactId>boot-community-demo</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>boot-community-demo-site</artifactId>
    <packaging>war</packaging>

    <name>Community Demo Site</name>
    <description>Web Module For Customized Broadleaf Commerce Site</description>

    <properties>
        <debug.port>8000</debug.port>
    </properties>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.mycompany-community</groupId>
            <artifactId>boot-community-demo-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>broadleaf-framework-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-solr</artifactId>
        </dependency>
        <!--
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-hsql-database</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-database</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>  
        <dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>broadleaf-thymeleaf3-presentation</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.zhanhb</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>        
    </dependencies>

</project>

Solution

  • Okay, we figured it out. I wanted to share the steps we took as it was a combination of steps/information from different sources (both BLC and Spring Boot sites).


    Step 1: The BLC codebase

    Download the source from: https://github.com/BroadleafCommerce/DemoSite

    The file I used was "DemoSite-develop-5.2.x".

    Unzip that in a location that your IDE can view/access.


    Step 2: The IDE (Eclipse in this case)

    Follow the steps from this site (almost verbatim):

    https://www.broadleafcommerce.com/docs/core/current/getting-started/ide-setup/eclipse-setup

    You should now have the site, admin, and api running locally, talking to the internal HSQL database.


    Step 3: Change to a MySQL database.

    I pretty much followed these instructions, step-by-step (although I already had MySQL on my machine):

    https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/database-configuration/mysql#


    Step 4: BLC Project code/xml changes

    It all starts with this link:

    https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/deploying-a-.war-file

    Where you find out:

    Follow the steps in 87.1 of the following:

    https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file

    Basically:

    Then I created a "web.xml" file, (although I'm not 100% sure I needed this as my servlet container is Servlet 3.1 and the BLC docs say all this web.xml configuration is now handled by annotations).

    https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/using-a-web.xml

    Basically:


    Step 5: Tomcat changes

    Another link that has most (if not all) of what you need:

    https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/tomcat

    /bin

    /conf

    /webapps


    Step 6: Maven Clean and Install

    Within Eclipse, on each of the Site and Admin projects ("boot-community-site" and "boot-community-admin"), right-click and select Run As >> Maven clean. Once that's finished run Run As >> Maven install.

    Now in each project's "target" directory, you should see a WAR file, ("ROOT" for the Site project and "admin" for the Admin project).


    Step 7: Start the Tomcat server

    I started the Tomcat server with the resident apps (docs, examples, host-manager, manager, and ROOT) untouched. I then hot-deployed the BLC "admin.war" and "ROOT.war" (site) to the Tomcat /webapps directory.

    If this doesn't work for you, you can always stop the Tomcat server and place both ROOT.war and admin.war files in the /webapps directory. Then start the server.

    If all goes well, viewing the "catalina.out" log file upon startup and you'll see an ASCII "Broadleaf Commerce" message scroll by, once for each BLC app, followed by a bunch of MySQL Hibernate messages. The entire startup time seems to be about 4 minutes for both Site and Admin on an "m5.large" AWS EC2 instance.

    I'll add to this as I think of what I've missed, but I now have BLC 5.2 running on a Tomcat 8.5 container.

    Hope it's of some use to others out there with the same issue I had.