三年没写博客了。把这篇记下来可能方便后来人——
目的:JBPM5.4里的demo,迁至MySQL数据库
按照手册里的步骤(jbpm-docs.pdf 3.7章节),跑出一堆问题的。而且很容易发现,手册是5.2版本的,具体可以在JBPM的GITHUB上观察。
错误1:
Table 'jbpm5.task' doesn't exist
数据源配置问题,解决方法看后面
错误2:
JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors)
数据源配置问题,解决方法看后面
错误3:
jbpm5 Unknown table 'sequences' in information_schema
数据源配置问题,解决方法看后面
错误4:
cvc-complex-type.4: Attribute 'type' must appear on element 'bpmn2:relationship'.
可以不用理会,参考:
https://community.jboss.org/thread/215959
具体说一下数据库配置,部分参考自:
https://community.jboss.org/message/785244#785244
好,正文开始:
修改文件
jbpm-installer\db\jbpm-persistence-JPA2.xml
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
修改文件jbpm-installer\db\task-persistence-JPA2.xml
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
修改文件jbpm-installer\task-service\resources\META-INF\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/task" />
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
</properties>
注意这个文件里还有个错误:
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Deadline</class>
重复了,去掉一遍
修改文件jbpm-installer\standalone.xml
注意这里要配2个数据源,而非手册上的一个:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/taskDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/task</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
<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>root</user-name>
<password></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>
</datasources>
</subsystem>
解压:
jbpm-installer\lib\jbpm-gwt-console-server-5.4.0.Final-EE6.war
修改
WEB-INF\classes\META-INF\persistence.xml
<jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
以及
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
再重新打包成war
解压
jbpm-installer\lib\jbpm-human-task-war-5.4.0.Final-EE6.war
修改
WEB-INF\classes\META-INF\persistence.xml
<non-jta-data-source>java:jboss/datasources/taskDS</non-jta-data-source>
以及
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
然后重新打包成war
接下来生成数据库脚本
编辑:jbpm-installer\build.properties,配置使用数据库为mysql(内有模板),注掉原来的H2部分
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
执行
ant jbpm.schemaexport
ant ht.schemaexport
就可以在jbpm-installer\db目录下找到mysql 的schema(htschemaexport.sql,jbpmschemaexport.sql),分别到jbpm5、task两个实例里面把数据库建立好
最后启动jboss7,如果之前安装过了,要重新clean一下(当然你如果找到到以上配置在哪里也可以手动替换)
执行
ant clean.demo.noeclipse
ant install.demo.noeclipse
ant start.demo.noeclipse
再启动后看log,除了那个可以忽略的错误,全都ok了,接下来在console里面操作,mysql里面观察吧