Search code examples
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.

    • Admin: https: //localhost:8444/admin
    • Site: https: //localhost:8443/
    • API: https: //localhost:8445/api/v1/swagger-ui.html

    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:

    • Deploying a .war file
    • Where is my web.xml?

    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:

    • SpringBootServletInitializer in SiteApplication.java
    • <packaging>war</packaging>
    • The "spring-boot-starter-tomcat" lines in the pom.xml file.

    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:

    • BroadleafBootServletContextInitializer in SiteApplication.java
      • You'll note that we added "SpringBootServletInitializer" previously.
      • Now we replace that "SpringBootServletInitializer" with "BroadleafBootServletContextInitializer".
    • Add the "web.xml" you'll find at the bottom of the page.
    • Don't forget to change the "param-value" of the "context-param" tags to your correct package location.

    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

    • New "setenv.sh" file containing:

      export CATALINA_OPTS="-Xmx1536M -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
      

    /conf

    • context.xml - Uncomment the following line

      `<Manager pathname="" />`
      
    • somenamehere-keystore (Needs to be generated, or grab the one in the BLC codebase)

    • server.xml - Added the HTTPS Connector:

      <Connector SSLEnabled="true" 
              clientAuth="false" 
              keystoreFile="/path/to/server/apache-tomcat-8.5.29/conf/*somenamehere*.keystore" 
              keystorePass="BLCPassword" 
              keyPass="BLCPassword" 
              keystoreType="PKCS12"
              ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA"
              maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLSv1.2"/>
      
      
      
      Note that I had to add the "keystoreType" attribute due to 
      my keystore being in the PKCS12 format, as opposed to JKS.
      
      The "ciphers" attribute was added as I got an exception 
      complaining about the TLS I was using.
      
    • tomcat-users.xml

      Added the following two lines:
      
      <role rolename="manager-gui"/>
      <user username="admin" password="ReallyHardToGuessPW" roles="manager-gui,admin-gui"/>
      
      I'm not sure if this step was 100% needed, but it allows me 
      to see the BLC projects within the "manager" app of Tomcat.
      

    /webapps

    • host-manager and manager apps

      In the "META-INF" of these apps I commented out both the "Valve" and "Manager" 
      tags in the "Context".
      
      This was extracted from this link:
      
          https://www.howtoforge.com/tutorial/how-to-install-apache-tomcat-8-5-on-ubuntu-16-04/
      
      (Look at "Step 6")
      
      This appears to be the only difference in my earlier attempts in 
      getting this running (pre-cry-for-SO-help), as yesterday and this 
      morning I had already performed all the steps in this post.   
      

    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.