Thứ Sáu, 13 tháng 4, 2012

How to change the default database of Activiti

This tutorial will guide you how to change the default database of Activiti (H2 database) to MySQL. We probably use another database except the database cannot support for Activiti. This is the list of databases can be used:

Activiti database type

Versions tested

Example jdbc url

Notes

h2

1.2.132

jdbc:h2:tcp://localhost/activiti

Default configured database

mysql

5.1.11

jdbc:mysql://localhost:3306/activiti?autoReconnect=true

Tested using mysql-connetor-java database driver

oracle

10.2.0

jdbc:oracle:thin:@localhost:1521:xe

postgres

8.4

jdbc:postgresql://localhost:5432/activiti

db2

DB2 9.7 using db2jcc4

jdbc:db2://localhost:50000/activiti

[EXPERIMENTAL]

mssql

2008 using JDBC jtds-1.2.4

jdbc:jtds:sqlserver://localhost:1433/activiti

[EXPERIMENTAL]

(according to the Activiti user guide for 5.8)

Ok, before we start, I think we better know that I used {activiti-home} to present the path of the directory where activiti is located.

Step 01: download the activiti's source codes. It probably named activiti-5.8.zip from Activiti's website. Unzip that zip file and make sure the file: {activiti-home}/setup/build.db.properties has the contents like below:
db=mysql
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/activiti
jdbc.username=
jdbc.password=

step 02: create sql file
just need to duplicate the file h2.data.sql in directory: {activiti-home}/setup/files/demo and change file name to mysql.data.sql.

step 03(optional): if you want to use the custom tomcat instead of the default tomcat
open the file {activiti-home}/setup/build.properties
look for download.dir entry and change the value to the directory which contains file apache-tomcat-{your-version}.zip

step 04: copy mysql-connector-java-5.1.6.jar to the directory below:

{activiti-home}/setup/files/dependencies

and also add this line to file {activiti-home}/workspace/activiti-engine-examples/.classpath
(be sure the name of jar file must match)


modify the listed text file below to add "mysql-connector-java-5.1.6.jar":
- {activiti-home}/setup/files/dependencie/libs.engine.test.txt
- {activiti-home}/setup/files/dependencie/libs.webapp.explorer.txt
- {activiti-home}/setup/files/dependencie/libs.webapp.rest.txt

step 05: modify the {activiti-home}/setup/build.xml file
+ looking for the target demo.start and delete(delete or disable are also suitable) the depends: h2.start
+ looking for the target demo.install and comment out the following tags:



step 06: run ant script demo.start
step 07:
+ stop Tomcat.
+ change {activiti-home}/apps/apache-tomcat-6.0.32/webapps/activiti-rest/WEB-INF/classes/activiti.cfg.xml point to mysql
+ start Tomcat