1 概述
本文主要講解jbpm+tomcat+mysql配置過程,程序用例爲jBPM自帶例子websale。主要環境內容如下:
Ø IDE:Eclipse3.2.1
Ø JDK:J2SDK1.5.06
Ø Tomcat:Tomcat5.5.17
Ø jBPM:jbpm-starters-kit-3.1.2
Ø Database:MySQL5.0.27
2 環境準備
2.1 安裝JDK1.5.06
去java.sun.com下載JDK1.5.06安裝文件。
雙擊JDK1.5.06安裝文件,安裝JDK1.5.06。安裝完成後,在系統環境變量中設置JAVA_HOME,並指向JDK1.5.06安裝目錄。後面稱爲JAVA_HOME。
2.2 安裝Eclipse3.2.1
去www.eclipse.org下載Eclipse3.2.1壓縮包。
將下載的Eclipse3.2壓縮包,解壓到系統某個目錄(D:\eclipse),後面稱爲ECLIPSE_HOME。
2.3 安裝Tomcat5.5.17
去http://www.apache.org/下載Tomcat5.5.17安裝文件。
雙擊Tomcat5.5.17安裝文件,安裝Tomcat5.5.17到系統某個目錄(D:\Tomcat5.5),後面稱爲TOMCAT_HOME。
2.4 安裝MySQL5.0.27
去http://www.mysql.com/下載mysql-5.0.27-win32.zip壓縮文件。
解壓該文件後,雙擊MySQL5.0.27安裝文件,安裝MySQL5.0.27到系統某個目錄(D:\Tomcat5.5),後面稱爲MySQL_HOME。
2.5 下載jBPM3.1.2
jBPM的下載地址:http://www.jboss.com/products/jbpm/downloads
² JBoss jBPM是jBPM 的軟件包
² JBoss jBPM Starters Kit是一個綜合包,它包括了jBPM軟件包、開發插件、一個配置好了的基於JBoss的jBPM示例、一些數據庫配置文件示例。
² JBoss jBPM Process Designer Plugin是輔助開發jBPM的Eclipse 插件。
² JBoss jBPM BPEL Extension jBPM關於BPEL的擴展包
本指南選擇下載:JBoss jBPM Starters Kit 3.1.2。下載後解壓到 D:\jbpm-starters-kit-3.1.2,後面簡稱JBPM_HOME。目錄下含有五個子目錄:
² jbpm jBPM的軟件包,包含源碼,例子等文件內容。
² jbpm-bpel只含有一個網頁
² jbpm-db各種數據庫hibernate配置文件示例,有些還包含了相應的jdbc驅動程序。
² jbpm-designer輔助開發jBPM的Eclipse插件,具體在jbpm-gpd-feature子目錄中
² jbpm-server一個已經配置好了的基於JBoss的jBPM示例。
2.6 安裝jBPM的Eclipse開發插件
有個輔助工具開發起來方便一點,只不過現在 jBPM 的開發工具插件功能還不算太強,也就一個“項目創建嚮導”的功能,讓你:
² 不用再去配置classpath庫的引用了
² 直接得到了一個jBPM的項目初始結構
其實吧,開發jBPM也不需要什麼插件工具,在熟練了以後,庫引用了項目初始結構都可以手工創建。
插件不用再去下載了,jbpm-starters-kit-3.1.2包裏就有,目錄地址如下: D:\jbpm-starters-kit-3.1.1\jbpm-designer\jbpm-gpd-feature\eclipse,插件的安裝方式是鏈接式還是直接複製式,另外,註明一下Eclipse的版本我是用3.2.1,插件和Eclispe版本相關的,要注意了。
如果安裝成功,則Eclipse首選項裏多了一個JBoss jBPM,另外我們也需要到這個jBPM的首選項裏做一些配置工作――指定jBPM的安裝路徑(如下圖所示)。這個配置主要是爲了找到jbpm下的各種jar包,好讓Eclipse設置項目的庫引用。
例如新建一個jbpm的工程後,其目錄樹結構如下圖所示:
3 具體配置情況
3.1 更改工程名稱
在JBPM_HOME\jbpm目錄下找到文件“.project”,用記事本打開,將以下內容<name>jbpm.3_BRANCH_3_1</name>更改爲<name>jbpm.3</name>,保存文件。
在將JBPM_HOME\jbpm文件夾更改爲JBPM_HOME\jbpm.3。後面引用工程名稱爲jbpm.3。
3.2 導入工程
啓動eclipse,通過“Import”將jBPM工程導入eclipse中。如下圖所示:
圖(1) 選擇已經存在的工程
圖(2) 選擇工程
點擊“Finish”完成導入,導入後的工程情況如下圖所示:
圖(3) 工程結構圖
3.3 建庫
在MySQL中建立數據庫jbpm。字符集採用GBK。建表SQL如下:
CREATE DATABASE `jbpm` CHARACTER SET 'gbk' COLLATE 'gbk_chinese_ci'; |
3.4 添加MySQL驅動
在工程jbpm.3的lib目錄下建立mysql文件夾,將MySQL需要的JDBC驅動程序拷貝其中。目錄結構如下圖所示:
圖(4) MySQL驅動位置
3.5 建立數據庫表
3.5.1 創建create.db.hibernate.properties
在工程jbpm.3的src/resources目錄下建立mysql目錄,並將jbpm.3/src/resources/hsqldb目錄下的所有文件(create.db.hibernate.properties和identity.db.xml)拷貝入mysql中。目錄結構如下圖所示:
圖(5) MySQL的create.db.hibernate.properties文件位置
3.5.2 修改create.db.hibernate.properties
在eclipse中,雙擊工程jbpm.3/src/resources/mysql下的create.db.hibernate.properties,打開該文件,修改其中的內容。
修改前內容:
hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.url=jdbc:hsqldb:hsql://localhost:1701 hibernate.connection.username=sa hibernate.connection.password= hibernate.show_sql=true |
修改後內容:
hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/jbpm hibernate.connection.username=root hibernate.connection.password=root hibernate.show_sql=true |
修改完後,保存並關閉文件。
3.5.3 修改build.deploy.xml
在eclipse中打開工程jbpm.3下的build.deploy.xml文件,在
<targetname="create.db"depends="declare.jbpm.tasks, db.clean, db.start" description="creates a hypersonic database with the jbpm tables and loads the processes in there"> |
之前,添加如下內容:
<target name="create.db.mysql" depends="declare.jbpm.tasks" description="creates a mysql database with the jbpm tables and loads the processes in there. Run this target after starting mysql"> <jbpmschema actions="create" cfg="${basedir}/src/config.files/hibernate.cfg.xml" properties="${basedir}/src/resources/mysql/create.db.hibernate.properties"/> <loadidentities file="${basedir}/src/resources/mysql/identity.db.xml" cfg="${basedir}/src/config.files/hibernate.cfg.xml" properties="${basedir}/src/resources/mysql/create.db.hibernate.properties"/> <antantfile="build.xml" target="build.processes" inheritall="false"/> <deployprocess cfg="${basedir}/src/config.files/hibernate.cfg.xml" properties="${basedir}/src/resources/mysql/create.db.hibernate.properties"> <filesetdir="build"includes="*.process"/> </deployprocess> </target> |
<property file="${basedir}/src/resources/mysql/create.db.hibernate.properties"/> <target name="execute.mysql.sql" description="execute a mysql sql script with -Dmysql.script=path-to-script."> <sql driver="${hibernate.connection.driver_class}" url="${hibernate.connection.url}"userid="${hibernate.connection.username}" password="${hibernate.connection.password}" delimiter=";" autocommit="true" οnerrοr="continue"> <classpath refid="classpath.ant"/> <transaction src="${mysql.script}"/> </sql> </target> |
3.5.4 生成庫表
在eclipse中,右鍵點擊工程jbpm.3下的build.deploy.xml文件,在菜單中選擇“Run As\Ant Build…”,在出現的窗口中選擇“target”爲“create db mysql”,然後點擊“Run”按鈕,開始運行Ant。
圖(6) Ant建立庫表
等運行完畢後,可以在MySQl中查看到相應得數據庫表結構已經建立,並且已經部署了websale需要用到的流程信息。
圖(7) jbpm_processdefinition表中的流程名稱
圖(8) jbpm_variableaccess表中信息
3.6 建立web運行需要內容
3.6.1 修改hibernate.cfg.xml
在eclipse中打開工程jbpm.3下的src/config.files目錄下的hibernate.cfg.xml文件,修改其中的內容爲:
<!-- jdbc connection properties --> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.connection.url"> jdbc:mysql://127.0.0.1:3306/jbpm </property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <!-- other hibernate properties --> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">false</property> <property name="hibernate.use_sql_comments">false</property> |
注意,只修改跟數據庫連接有關的內容,這裏你可以根據自己數據庫的不同,而建立不同的hibernate連接。
3.6.2 修改build.deploy.xml
在eclipse中打開工程jbpm.3下的build.deploy.xml文件,找到如下“target”,
<targetname="build.webapp"description="builds jbpm.war"> <antantfile="build.xml"target="build.webapp"/> <mkdirdir="build/jbpm.war.dir"/> <copytodir="build/jbpm.war.dir"> <filesetdir="src/resources/jbpm.war"/> </copy> ……………………………………… <jardestfile="build/jbpm.war"> <filesetdir="build/jbpm.war.dir"/> </jar> </target> |
並將此“target”內容更改爲如下內容:
<targetname="build.webapp"description="builds jbpm.war"> <antantfile="build.xml"target="build.webapp"/> <mkdirdir="build/jbpm.war.dir"/> <copytodir="build/jbpm.war.dir"> <filesetdir="src/resources/jbpm.war"/> </copy> <copytodir="build/jbpm.war.dir/WEB-INF/classes"> <filesetdir="src/config.files"/> </copy> <copytodir="build/jbpm.war.dir/WEB-INF/lib"> <filesetdir="build" includes="jbpm*.jar,converter.jar" excludes="*src*.jar"/> <filesetdir="lib/jsf"includes="*.jar"/> <filesetdir="lib/dom4j"includes="*.jar"/> <filesetdir="lib/hibernate"includes="*.jar"/> <filesetdir="lib/mysql"includes="*.jar"/> <filesetdir="lib/commons" includes="commons-digester-*.jar, commons-beanutils-*.jar, commons-fileupload-*.jar"/> <filesetdir="lib/jboss" includes="*.jar" excludes="jboss*.jar, *servlet*.jar, *hsql*.jar"/> </copy> <jardestfile="build/jbpm.war"> <filesetdir="build/jbpm.war.dir"/> </jar> </target> |
3.6.3 打包成war文件
在eclipse中,右鍵點擊工程jbpm.3下的build.deploy.xml文件,在菜單中選擇“Run As\Ant Build…”,在出現的窗口中選擇“target”爲“build webapp”,然後點擊“Run”按鈕,開始運行Ant。
圖(9) Ant打包war文件
3.7 發佈應用
在工程jbpm.3下build目錄中,將jbpm.war文件拷貝到TOMCAT_HOME\webapps目錄下。啓動Tomcat。啓動完成後,日誌會不斷輸出,其中最後一句是“DEBUG [StaticNotifier] going to wait for (CMD_EXECUTOR, java.lang.Object@1df59bd) ”,這表示 jBPM 在開始工作了,它不斷進行輪詢。
在瀏覽器中輸入地址http://localhost:8080/jbpm,出現登錄頁面,配置成功。
4 運行應用
打開網頁:http://localhost:8080/jbpm/得到如下畫面
圖(10) 登錄界面
這是一個已經用jBPM開發好的用戶定單流程,具有下單、審覈、估價等流程。
以cookie monster用戶登錄,選擇“create new web sale order”可以創建一個定單。如下圖所示,在圖左邊是填寫的定單情況,右邊一整個定貨流程的示意圖,紅色框表示流程進行到哪一步了。填寫好定單好,選擇“Save and Close Task”,完成定單提交。
圖(11) 創建新任務
選擇右上角的“Login as another user”以另外一個用戶名ernie登錄。這時可以看到ernie用戶的任務列表中多了一項。
圖(12) 處理任務
點進去後,顯示如下畫面。在 comment 項填寫意見,選 OK 按鈕,進入到下一步。如果選擇 more info needed 按鈕,則打回給 cookie monster 用戶修改定單。
圖(13) 處理內容
5 結束語
本文比較簡單的闡述了jbmp與mysql與tomcat之間的配置管理。對於其他數據庫以及web容器其方式是一樣的,可參照本配置指南進行相關配置。