Recently just contacted Broadleaf commerce, an open source template for e-commerce websites. Specific operation and configuration can refer to the link: Click to open the link
The template is run under the Jetty container, and the database is hsql. The official website shows how to migrate the database to MySQL and deploy the project to Tomcat in the configuration required, but the process is not very detailed, the resources on the net is not many, so the landlord intends to write this blog as a summary.
1. Migration of databases (Hsql to MySQL)
(a) Open the Pom.xml file in the root directory of the Demosite project,<dependencyManagement>区域中添加:
<dependency> <groupId>mysql</groupId> <artifactid>mysql-connector-java</ artifactid> <version>5.1.26</version> <type>jar</type>
(b) Locate Pom.xml open in the admin and site folders, respectively, and
<dependencies>
Area to add:
<dependency> <groupId>mysql</groupId>
(c) Adding database named broadleaf to MySQL database
(d)分别打开admin/src/main/webapp/META-INF和admin/src/main/webapp/META-INF
中的context.xml,将内容替换如下(数据库相关的配置信息如用户名和密码请根据自身的环境作相应的修改):
<?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= "SEL ECT 1 "timebetweenevictionrunsmillis=" 30000 "maxactive=" "maxidle=" 10 " Minidle= "5" removeabandonedtimeout= "removeabandoned=" false "logabandoned=" tr UE "minevictableidletimemillis=" 30000 "jdbcinterceptors=" org.apache.tomcat.jdbc.pool.interceptor . Connectionstate;org.apache.tomcat.jdbc.pool.interceptor.statementfinalizer "username=" root "pass Word= "123" Driverclassname= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/broadleaf"/& Gt <resource NamE= "Jdbc/storage" auth= "Container" type= "Javax.sql.DataSource" factory= "org.apache.t Omcat.jdbc.pool.DataSourceFactory "testwhileidle=" true "testonborrow=" true "Testonr Eturn= "false" validationquery= "SELECT 1" timebetweenevictionrunsmillis= "30000" MaxA Ctive= "maxidle=" minidle= "5" removeabandonedtimeout= "Remove" Abandoned= "false" logabandoned= "true" minevictableidletimemillis= "30000" Jdbcinterc Eptors= "Org.apache.tomcat.jdbc.pool.interceptor.connectionstate;o Rg.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer "username=" root "password=" 123 " Driverclassname= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/broadleaf"/> <resour Ce 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" Timebetwe Enevictionrunsmillis= "30000" maxactive= "maxidle=" minidle= "5" R Emoveabandonedtimeout= "removeabandoned=" false "logabandoned=" true "minevictable Idletimemillis= "30000" jdbcinterceptors= "org.apache.tomcat.jdbc.pool.interceptor.connectionstate;org.apache.t Omcat.jdbc.pool.interceptor.StatementFinalizer "username=" root "password=" 123 "Driv Erclassname= "Com.mysql.jdbc.Driver" url= "Jdbc:mysql://localhost:3306/broadleaf"/></context>
(e) Open the core/src/main/resources/runtime-properties/common-shared.properties
file with the following three articles
blpu.hibernate.dialect=org.hibernate.dialect.hsqldialectblcmsstorage.hibernate.dialect= Org.hibernate.dialect.hsqldialectblsecurepu.hibernate.dialect=org.hibernate.dialect.hsqldialect
To be replaced by:
blpu.hibernate.dialect=org.hibernate.dialect.mysql5innodbdialectblsecurepu.hibernate.dialect= org.hibernate.dialect.mysql5innodbdialectblcmsstorage.hibernate.dialect= Org.hibernate.dialect.MySQL5InnoDBDialect
(f) Open the build.properties in the Demosite root directory with the following
ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.hsqldialectant.blpu.url=jdbc:hsqldb:hsql://localhost/ Broadleafant.blpu.username=saant.blpu.password=nullant.blpu.driverclassname= Org.hsqldb.jdbcdriverant.blsecurepu.url=jdbc:hsqldb:hsql://localhost/broadleafant.blsecurepu.username= SAANT.BLSECUREPU.PASSWORD=NULLANT.BLSECUREPU.DRIVERCLASSNAME=ORG.HSQLDB.JDBCDRIVERANT.BLCMSSTORAGE.URL=JDBC: hsqldb:hsql://localhost/broadleafant.blcmsstorage.username=saant.blcmsstorage.password= Nullant.blcmsstorage.driverclassname=org.hsqldb.jdbcdriver
Modify the configuration according to your own database to:
Ant.hibernate.sql.ddl.dialect=org.hibernate.dialect.mysql5innodbdialectant.blpu.url=jdbc:mysql://localhost : 3306/broadleafant.blpu.username=rootant.blpu.password=123ant.blpu.driverclassname= Com.mysql.jdbc.driverant.blsecurepu.url=jdbc:mysql://localhost:3306/broadleafant.blsecurepu.username= ROOTANT.BLSECUREPU.PASSWORD=123ANT.BLSECUREPU.DRIVERCLASSNAME=COM.MYSQL.JDBC.DRIVERANT.BLCMSSTORAGE.URL=JDBC: mysql://localhost:3306/broadleafant.blcmsstorage.username=rootant.blcmsstorage.password= 123ant.blcmsstorage.driverclassname=com.mysql.jdbc.driver
This makes the migration of the database complete.
2.服务器的迁移(从jetty到tomcat7)
(a)在site和admin目录下的pom.xml文件的中<plugins>区域中分别添加:
<plugin> <groupid>org.apache.tomcat.maven</groupid& Gt <artifactId>tomcat7-maven-plugin</artifactId> <version>2.0</version> ; <configuration> <warsourcedirectory>${webappdirectory}</warsourcedir Ectory> <path>/</path> <po Rt>${httpport}</port>
(b)在eclipse中右键DemoSite工程,先后运行Run As里面的Maven clean和Maven install,成功后就会在DemoSite中的admin和site的target文件夹中有相应的war包生成,楼主生成的两个war包名为admin.war和zk.war。
(c)楼主的环境是ubuntu,tomcat服务器中webapps的路径为/var/lib/tomcat7/webapps,将admin和zk.war拷贝到该目录下,然后重启tomcat服务器:
SUDO/ETC/INIT.D/TOMCAT7 restart
See/var/log/tomcat7/catalina.out file error as follows:caused By:java.lang.OutOfMemoryError:Java heap space at Org.apache.tomcat.util.bcel.classfile.ClassParser.readMet Hods (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.C Ore. 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) A T 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 problem is memory overflow, the specific solution is as follows:
In Ubuntu, modify the catalina.sh file (the path of this file is/usr/share/tomcat7/bin/catalina.sh), add the following in the first line of the file:
java_opts= '-server-xms256m-xmx512m-xx:permsize=128m-xx:maxpermsize=256m ' #注意: Single quotes cannot be omitted
Modify the Catalina.bat file in Windows and add the following in the first line:
Set java_opts=-server-xms256m-xmx512m-xx:permsize=128m-xx:maxpermsize=256m #注意: no single quotation mark
(d) Restart the Tomcat server following the completion of the modifications in (c):
SUDO/ETC/INIT.D/TOMCAT7 restart
You can open the e-commerce page normally in the browser: Localhost:8080/zk and Admin page: localhost:8080/admin, the migration to the Tomcat server is done.