参考博文:http://blog.csdn.net/dcl8261425/article/details/6575797
首先需要安装JBPM5和MYSQL。。。。
一、修改JBPM持久化相关配置文件
1、jbpm-installer/db/hibernate.cfg.xml
注释部分为原h2数据库的配置,下同。
<hibernate-configuration> <session-factory> <!-- Database connection settings --> <!--<property name="connection.driver_class">org.h2.Driver</property>--> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!--<property name="connection.url">jdbc:h2:tcp://localhost/~/test</property>--> <property name="connection.url">jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8</property> <!--property name="connection.url">jdbc:h2:file:/NotBackedUp/data/mydb</property--> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <!--<property name="dialect">org.hibernate.dialect.H2Dialect</property>--> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">false</property> <!-- Drop and re-create the database schema on startup? --> <property name="hbm2ddl.auto">create</property> <mapping resource="AuditLog.hbm.xml"/> </session-factory> </hibernate-configuration>
2.jbpm-installer/db/persistence.xml
jta-data-source那一项匹配的是testDS1-ds.xml中jndi-name,自行修改
<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:jdbc/jbpmDatasource</jta-data-source> <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class> <class>org.drools.persistence.info.SessionInfo</class> <class>org.drools.persistence.info.WorkItemInfo</class> <!-- <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="false" /> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> </properties> --> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8" /> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="root"/> <property name="hibernate.connection.autocommit" value="true" /> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit>
3.jbpm-installer/db/testDS1-ds.xml
<datasources> <!-- <local-tx-datasource> <jndi-name>jdbc/testDS1</jndi-name> <connection-url>jdbc:h2:tcp://localhost/~/test</connection-url> --><!--connection-url>jdbc:h2:mem:mydb</connection-url--><!-- <driver-class>org.h2.jdbcx.JdbcDataSource</driver-class> <user-name>sa</user-name> <password></password> </local-tx-datasource>--> <jndi-name>jdbc/jbpmDatasource</jndi-name> <connection-url>jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8</connection-url> <!--connection-url>jdbc:h2:mem:mydb</connection-url--> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>root</user-name> <password>root</password> </datasources>
4.jbpm-installer/runtime/jbpm-bam.jar/hibernate.cfg.xml
<hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8</property> <!--property name="connection.url">jdbc:h2:file:/NotBackedUp/data/mydb</property--> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">false</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <mapping resource="AuditLog.hbm.xml"/> </session-factory> </hibernate-configuration>
5.jbpm-installer/runtime/jbpm-human-task-{version}.jar/persistence.xml
<properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8" /> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="root"/> <property name="hibernate.connection.autocommit" value="true" /> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="false" /> </properties>
二、相关jar包
mysql驱动包放在jbpm-installer/db/driver中
下载slf4j相关包,http://www.slf4j.org/download.html
下载btm-1.3.2.jar
三、编写TaskServer.java
需要导入JAR包:btm-1.3.2.jar、slf4j-jdk14-1.6.2.jar、mysql驱动包
标注的些地方换成自己相关的就行了
public static final void main(String[] args) { try { PoolingDataSource ds1 = new PoolingDataSource(); ds1.setUniqueName( "jdbc/jbpmDatasource" );//这里 ds1.setClassName( "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" ); ds1.setMaxPoolSize( 3 ); ds1.setAllowLocalTransactions( true ); //下面数据库相关 ds1.getDriverProperties().put( "user", "root" ); ds1.getDriverProperties().put( "password", "root" ); ds1.getDriverProperties().put( "URL", "jdbc:mysql://localhost:3306/jbpm?useUnicode=true&characterEncoding=UTF-8" ); ds1.init(); EntityManagerFactory emfTask = Persistence.createEntityManagerFactory( "org.jbpm.task" ); TaskService taskService = new TaskService(emfTask, SystemEventListenerFactory.getSystemEventListener()); /* * Add the required users */ TaskServiceSession taskSession = taskService.createSession(); taskSession.addUser(new User("Administrator")); taskSession.addUser(new User("krisv")); taskSession.addUser(new User("john")); taskSession.addUser(new User("mary")); /* Start Mina server for HT*/ MinaTaskServer server = new MinaTaskServer(taskService); Thread thread = new Thread(server); thread.start(); System.out.println("Server started ..."); } catch (Throwable t) { t.printStackTrace(); } }
好了,剩下的启动TaskServer然后运行下sample中的evaluation试试,完成human task中的任务,没有出错就一切OK了