Set up jBPM 5.4 Final Installer to use MySQL - or how to run section 3.7 of the User Guide

Version 3

    I've started using jBPM 5.4 a couple weeks ago. It's my first forray into jBPM and I am slowly working through the user guide. I go to 3.7. 10-Minute Tutorial: Using your own database with jBPM and got stuck.

    First of all, credits. I thank Thomas Setiabudi for posting the wonderful article titled Set up JBPM5.4 Final Installer to use MS SQL Server 2008 using JTDS which I used for inspiration.

    Second, shameless plug - my forray into jBPM which I will update as I make my way through the user guide.

    And, last, but not least, the information,

     

    My OS Ubuntu Desktop 12.04. If you are using Windows, be aware that you will have to rewrite paths with the backslashes "\" appropriate for your system..

     

    The article is split into four steps:

    • Set up MySQL
    • Set up jBPM
    • Install jBPM
    • Run the demo using your own Database

     

    Set up MySQL

    With MySQL installed, log in as the root user and run the following commands from the mysql> prompt:

     

    mysql> CREATE SCHEMA IF NOT EXISTS jbpm5;
    mysql> CREATE USER 'jbmp5'@'localhost' IDENTIFIED BY 'jbpm5';
    mysql> GRANT ALL PRIVILEGES ON jbpm5.* TO 'jbpm5'@'localhost';
    

     

    mysql> CREATE SCHEMA IF NOT EXISTS task;
    mysql> CREATE USER 'task'@'localhost' IDENTIFIED BY 'task';
    mysql> GRANT ALL PRIVILEGES ON task.* TO 'task'@'localhost;
    

     

    Set up jBPM

    First, run

    ant clean.demo
    

     

    Second, you will have to change the following files:

    • build.properties
    • build.xml
    • db/jbpm-persistence-JPA2.xml
    • db/task-persistence-JPA2.xml
    • standalone.xml
    • task-service/resources/META-INF/persistence.xml
    • lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml
    • lib/jbpm-human-task-war-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml

    build.properties

    Change

    # data base related properties
    db.driver.jar=${install.home}/db/driver/${db.driver.jar.name}
    db.driver.module.dir=${jboss.home}/modules/${db.driver.module.prefix}/main/
    # default is H2
    db.name=h2
    db.driver.jar.name=${db.name}.jar
    db.driver.download.url=http://repo1.maven.org/maven2/com/h2database/h2/${H2.version}/h2-${H2.version}.jar
    #other options are mysql
    #  db.name=mysql
    #  db.driver.module.prefix=com/mysql
    #  db.driver.jar.name=${db.name}-connector-java.jar
    #  db.driver.download.url=https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar
    #postresql
    #  db.name=postresql
    #  db.driver.module.prefix=org/postgresql
    #  db.driver.jar.name=${db.name}-jdbc.jar
    #  db.driver.download.url=https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/postgresql/postgresql/9.1-902.jdbc4/postgresql-9.1-902.jdbc4.jar
    

    To

    # data base related properties
    db.driver.jar=${install.home}/db/driver/${db.driver.jar.name}
    db.driver.module.dir=${jboss.home}/modules/${db.driver.module.prefix}/main/
    #  default is H2
    #  db.name=h2
    #  db.driver.jar.name=${db.name}.jar
    #  db.driver.download.url=http://repo1.maven.org/maven2/com/h2database/h2/${H2.version}/h2-${H2.version}.jar
    #other options are mysql
      db.name=mysql
      db.driver.module.prefix=com/mysql
      db.driver.jar.name=${db.name}-connector-java.jar
      db.driver.download.url=https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar
    #postresql
    #  db.name=postresql
    #  db.driver.module.prefix=org/postgresql
    #  db.driver.jar.name=${db.name}-jdbc.jar
    #  db.driver.download.url=https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/postgresql/postgresql/9.1-902.jdbc4/postgresql-9.1-902.jdbc4.jar
    

    build.xml

    In

    <!-- Start Demo -->
    <target name="start.demo" depends="start.h2,start.jboss,start.eclipse" />
    
    
    <!-- Start Demo (Eclipse) -->
    <target name="start.demo.eclipse" depends="start.h2,start.eclipse" />
    
    
    <!-- Start Demo (No Eclipse)-->
    <target name="start.demo.noeclipse" depends="start.h2,start.jboss" />
    
    
    <!-- Stop Demo -->
    <target name="stop.demo" depends="stop.h2,stop.jboss" />
    

    Add

    <!-- Start Demo -->
    <target name="start.demo" depends="start.h2,start.jboss,start.eclipse" />
    
    
    <!-- Start Demo (DB) -->
    <target name="start.demo.db" depends="start.jboss, start.eclipse" />
    
    
    <!-- Start Demo (DB, No Eclipse) -->
    <target name="start.demo.db.noeclipse" depends="start.jboss" />
    
    
    <!-- Start Demo (Eclipse) -->
    <target name="start.demo.eclipse" depends="start.h2,start.eclipse" />
    
    
    <!-- Start Demo (No Eclipse)-->
    <target name="start.demo.noeclipse" depends="start.h2,start.jboss" />
    
    
    <!-- Stop Demo -->
    <target name="stop.demo" depends="stop.h2,stop.jboss" />
    
    
    <!-- Stop Demo (DB)-->
    <target name="stop.demo.db" depends="stop.jboss" />
    

    db/jbpm-persistence-JPA2.xml

    Change

    <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
    

    To

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    

    db/task-persistence-JPA2.xml

    Change

    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    

    To

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    

    standalone.xml

    Change

    <datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true">
      <connection-url>jdbc:h2:~/jbpm</connection-url>
      <driver>h2</driver>
      <pool>
        <min-pool-size>1</min-pool-size>
        <max-pool-size>4</max-pool-size>
        <prefill>false</prefill>
        <use-strict-min>false</use-strict-min>
        <flush-strategy>FailingConnectionOnly</flush-strategy>
      </pool>
      <security>
        <user-name>sa</user-name>
      </security>
      <validation>
        <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
        <validate-on-match>false</validate-on-match>
        <background-validation>false</background-validation>
      </validation>
    </datasource>
    <drivers>
      <driver name="h2" module="com.h2database.h2">
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
      </driver>
    </drivers>
    

    To

    <datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true">
      <connection-url>jdbc:mysql://localhost:3306/jbpm5</connection-url>
      <driver>mysql</driver>
      <pool>
        <min-pool-size>1</min-pool-size>
        <max-pool-size>4</max-pool-size>
        <prefill>false</prefill>
        <use-strict-min>false</use-strict-min>
        <flush-strategy>FailingConnectionOnly</flush-strategy>
      </pool>
      <security>
        <user-name>jbpm5</user-name>
        <password>jbpm5</password>
      </security>
      <validation>
        <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
        <validate-on-match>false</validate-on-match>
        <background-validation>false</background-validation>
      </validation>
    </datasource>
    <drivers>
      <driver name="mysql" module="com.mysql">
        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
      </driver>
    </drivers>
    

    task-service/resources/META-INF/persistence.xml

    Change

    <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
    <property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
    <property name="hibernate.connection.url" value="jdbc:h2:tcp://localhost/runtime/task" />
    <property name="hibernate.connection.username" value="sa"/>
    <property name="hibernate.connection.password" value=""/>
    

    To

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.connection.driver_class" value="org.jdbc.Driver"/>
    <property name="hibernate.connection.url" value="jdbc:mysql:://localhost:3306/task" />
    <property name="hibernate.connection.username" value="task"/>
    <property name="hibernate.connection.password" value="task"/>
    

    lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml

    To edit this file, take advantage of the GUI. Navigate to the .war file using Nautilus and rely on File Roller to open the .war file. File Roller should come pre-installed on Ubuntu Desktop 12.04. Once you're inside the .war file, you can use gedit to open persistence.xml. When you save, File Roller will ask if you want to update the  archive and you must. On Window, 7-Zip can be used to open the .war file.

     

    Change

    <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
    

    To

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    

    lib/jbpm-human-task-war-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml

    To edit this file, take advantage of the GUI. Navigate to the .war file using Nautilus and rely on File Roller to open the .war file. File Roller should come pre-installed on Ubuntu Desktop 12.04. Once you're inside the .war file, you can use gedit to open persistence.xml. When you save, File Roller will ask if you want to update the  archive and you must. On Window, 7-Zip can be used to open the .war file.

     

    Change

    <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
    

    To

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    

    Install jBPM

    Run

     

    ant install.demo 

     

    This will install the jBPM demo and pull all the appropriate drivers and files for MySQL.

    Run the demo using your own Database

    To start the demo you can run

    ant start.demo.db
    

    or

    ant start.demo.db.noeclipse
    

     

    To stop the demo, run

    ant stop.demo.db