Recently broadleaf commerce, a business website open source template.

The model is run in the jetty container, the database is HSQL. The official website describes how to migrate the database to PosgreSQL and the project needed for deployment in Tomcat configuration, but the process is not very detailed, online resources in this area is not a lot, so I decided to write this blog as a summary.

Transfer 1 database (HSQL to POSGRESQL)

(a)Open the root directory of the DemoSite project pom.xml file, in the<dependencyManagement>Regional add:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.26</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

(b)Open and found in the pom.xml in the admin and site folders respectively<dependencies>Regional add:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

(c)Add a database named broadleaf in the MySQL database

(d)Open admin/src/main/webapp/META-INF and admin/src/main/webapp/META-INF in context.xml respectively, the content is replaced by the following (database configuration information such as user name and password please according to their own environment change accordingly):

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="jdbc/web"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="SELECT 1"
              timeBetweenEvictionRunsMillis="30000"
              maxActive="15"
              maxIdle="10"
              minIdle="5"
              removeAbandonedTimeout="60"
              removeAbandoned="false"
              logAbandoned="true"
              minEvictableIdleTimeMillis="30000"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
              username="root"
              password="123"
              driverClassName="com.postgresql.Driver"
              url="jdbc:mysql://localhost:3306/broadleaf"/>

    <Resource name="jdbc/storage"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="SELECT 1"
              timeBetweenEvictionRunsMillis="30000"
              maxActive="15"
              maxIdle="10"
              minIdle="5"
              removeAbandonedTimeout="60"
              removeAbandoned="false"
              logAbandoned="true"
              minEvictableIdleTimeMillis="30000"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
              username="root"
              password="123"
              driverClassName="com.postgresql.Driver"
              url="jdbc:mysql://localhost:3306/broadleaf"/>

    <Resource name="jdbc/secure"
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="SELECT 1"
              timeBetweenEvictionRunsMillis="30000"
              maxActive="15"
              maxIdle="10"
              minIdle="5"
              removeAbandonedTimeout="60"
              removeAbandoned="false"
              logAbandoned="true"
              minEvictableIdleTimeMillis="30000"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
              username="root"
              password="123"
              driverClassName="com.postgresql.Driver"
              url="jdbc:mysql://localhost:3306/broadleaf"/>
</Context>

(e)Open the core/src/main/resources/runtime-properties/common-shared.properties file, the following three

blPU.hibernate.dialect=org.hibernate.dialect.HSQLDialect
blCMSStorage.hibernate.dialect=org.hibernate.dialect.HSQLDialect
blSecurePU.hibernate.dialect=org.hibernate.dialect.HSQLDialect

Were replaced by:

blPU.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
blSecurePU.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
blCMSStorage.hibernate.dialect=org.hibernate.dialect.org.hibernate.dialect.PostgreSQLDialect

(f)Open the DemoSite build.properties in the root directory, the following contents

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.HSQLDialect

ant.blPU.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blPU.userName=sa
ant.blPU.password=null
ant.blPU.driverClassName=org.hsqldb.jdbcDriver

ant.blSecurePU.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blSecurePU.userName=sa
ant.blSecurePU.password=null
ant.blSecurePU.driverClassName=org.hsqldb.jdbcDriver

ant.blCMSStorage.url=jdbc:hsqldb:hsql://localhost/broadleaf
ant.blCMSStorage.userName=sa
ant.blCMSStorage.password=null
ant.blCMSStorage.driverClassName=org.hsqldb.jdbcDriver

According to their configuration changes to database:

ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.PostgreSQLDialect

ant.blPU.url=jdbc:postgresql://localhost:3306/broadleaf
ant.blPU.userName=root
ant.blPU.password=123
ant.blPU.driverClassName=org.postgresql.Driver

ant.blSecurePU.url=jdbc:postgresql://localhost:3306/broadleaf
ant.blSecurePU.userName=root
ant.blSecurePU.password=123
ant.blSecurePU.driverClassName=org.postgresql.Driver

ant.blCMSStorage.url=jdbc:postgresql://localhost:3306/broadleaf
ant.blCMSStorage.userName=root
ant.blCMSStorage.password=123
ant.blCMSStorage.driverClassName=org.postgresql.Driver

This database migration is complete.

Transfer 2 servers (from jetty to tomcat7)

(a)In the site and admin directory of the pom.xml file<plugins>Adding region:

                         <plugin>
                                <groupId>org.apache.tomcat.maven</groupId>
                                <artifactId>tomcat7-maven-plugin</artifactId>
                                <version>2.0</version>
                                <configuration>
                                        <warSourceDirectory>${webappDirectory}</warSourceDirectory>
                                        <path>/</path>
                                        <port>${httpPort}</port>
                                        <httpsPort>${httpsPort}</httpsPort>
                                        <keystoreFile>${webappDirectory}/WEB-INF/blc-example.keystore</keystoreFile>
                                        <keystorePass>broadleaf</keystorePass>
                                        <password>broadleaf</password>
                                </configuration>
                        </plugin>

(b)Right click DemoSite project in eclipse, Has run the Run As inside the Maven clean and Maven install, After the success will be in DemoSite admin and site target folder in the corresponding war packet generation, We generated two war package named admin.war and zk.war.

(c)Your environment is Ubuntu, the path to the webapps Tomcat server for /var/lib/tomcat7/webapps, admin and zk.war will be copied to the folder, and then restart the Tomcat server:

sudo /etc/init.d/tomcat7 restart

See the /var/log/tomcat7/catalina.out file error:

Caused by: java.lang.OutOfMemoryError: Java heap space
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:268)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:128)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2105)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1981)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1947)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1932)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1326)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        ... 4 more

Baidu later learned that the memory overflow problem, the following specific solutions:

Catalina.sh files in Ubuntu (path for the file is /usr/share/tomcat7/bin/catalina.sh), add the following content in the first line in the document:

JAVA_OPTS='-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M' #Note: single quotation marks can not be omitted

Catalina.bat files in windows, in the first row, add the following content:

set JAVA_OPTS=-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M #Note: no single quotation marks

(d)According to (c) in the modified after the restart the Tomcat server:

sudo /etc/init.d/tomcat7 restart

You can normal open electric page in the browser: localhost:8080/zk and background management page: localhost:8080/admin, to transfer Tomcat server also be accomplished.

Advertisements