1. 下载最新版本的 JBoss jBPM Starters kit。解压这个文件,假设解压目录为 "${jbpm.starters.kit}",它的下面应该有 jbpm, jbpm-bpel,jbpm-db,jbpm-designer,jbpm-server 五个子目录。其中我们要用到的是 jbpm 和 jbpm-db两个目录。

2. 导航到 jbpm-db 子目录。在该目录下可以找到 build.properties 文件。这个文件需要作一定修改才能使用。 找到下面的这段代码:

     jbpm.3.location=C:/jbpm-X.X   
     upgrade.hibernate.properties
=hsqldb/hibernate.properties   
     upgrade.libdir
=hsqldb/lib   
     upgrade.old.schema.script
=hsqldb/upgrade.scripts/hsqldb.create.jbpm.3.0.2.sql

    注意第一行,将 “C:/jbpm-x.x” 改成 "${jbpm.starters.kit}/jbpm"。

3. 导航到 jbpm 子目录。在 jbpm"src"config.files 路径下可以找到 hibernate.cfg.xml 文件。这个文件需要修改和数据库连接相关的部分。找到下面这行代码:

 <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>  
 
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>  
 
<property name="hibernate.connection.url">jdbc:hsqldb:mem:.;sql.enforce_strict_size=true</property>  
 
<property name="hibernate.connection.username">sa</property>  
 
<property name="hibernate.connection.password"></property>

将其修改成 Oracle 的格式:

 <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>  
 
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>  
 
<property name="hibernate.connection.url">jdbc:oracle:thin@localhost:1521:fred</property>  
 
<property name="hibernate.connection.username">FiberSchedulerJBPM</property>  
 
<property name="hibernate.connection.password">FiberSchedulerJBPM</property>
   导航到子目录 jbpm 下的路径 jbpm-db"oracle"lib,下载最新的 Oracle jdbc驱动程序(我使用的是 class14.jar),把它放在该路径下。
   其中 "localhost" 换成你自己的数据库所在的机器名(或者ip地址),"fred" 换成你自己的Oracle数据库的 SID 名字, 使用你自己的 Oracle 数据库用户名和密码来替换 "FiberSchedulerJBPM" 。
4. 导航到 jbpm-db 子目录,在 jbpm-db"oracle 路径下找到文件 hibernate.properties。找到下面这段代码:
 hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver   
 hibernate.connection.url
=jdbc:oracle:thin@HOST:PORT:SID   
 hibernate.connection.username
=USER   
 hibernate.connection.password
=PASSWORD 
根据你的数据库配置修改,我的修改如下:
   hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver   
  
hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:fred   
  
hibernate.connection.username=FiberSchedulerJBPM   
  
hibernate.connection.password=FiberSchedulerJBPM  

5. 在目录  jbpm-db下找到ant脚本 build.xml 文件,这个ant 脚本中有这样一段代码是用来生成数据库脚本的:
<target name="db.scripts" description="helper target to generate the database scripts" depends="prepare">  
   
<delete dir="build/${db}/scripts" />  
 
<mkdir dir="build/${db}/scripts" />  
 
<java classname="org.jbpm.db.JbpmSchema" fork="true">  
   
<classpath refid="classpath.${db}" />  
   
<arg value="scripts"/>    
   
<arg value="${basedir}/build/${db}/scripts"/>    
   
<arg value="${db}"/>    
    
<arg value="${jbpm.3.location}/src/config.files/hibernate.cfg.xml"/>    
    
<arg value="${basedir}/${db}/hibernate.properties"/>    
   java
>    
 target
>
这段脚本将调用 jBPM的类 org.jbpm.db.JbpmSchema.java 的 main 方法,并给他传5个参数。我们在目录 jbpm 的路线 jbpm"src"java.jbpm"org"jbpm"db 下找到类 JbpmSchema,打开它找到这么一段代码:
public static void main(String[] args) {   
  
try {   
    
if ( (args==null|| (args.length==0) ) {   
      
throw new IllegalArgumentException();   
     }   
       
     String cmd 
= args[0];   
       
    
if ("create".equalsIgnoreCase(cmd)) {   
       Configuration configuration 
= createConfiguration(args, 1);   
      
new JbpmSchema(configuration).createSchema();   
     } 
else if ("drop".equalsIgnoreCase(cmd)) {   
       Configuration configuration 
= createConfiguration(args, 1);   
      
new JbpmSchema(configuration).dropSchema();   
     } 
else if ("clean".equalsIgnoreCase(cmd)) {   
       Configuration configuration 
= createConfiguration(args, 1);   
      
new JbpmSchema(configuration).cleanSchema();   
     } 
else if ("scripts".equalsIgnoreCase(cmd)) {   
       Configuration configuration 
= createConfiguration(args, 3);   
      
new JbpmSchema(configuration).saveSqlScripts(args[1], args[2]);   
     }
显然,它只使用了ant脚本传给它的前三个参数。当生成非基于 Oracle 的数据库脚本时,前三个脚本足够了。问题是当生成基于 Oracle 的数据库脚本时,需要使用后两个参数。所以,我们在这段代码的后面加上:
    else if ((args != null&& (args.length > 3&& ("scripts".equalsIgnoreCase(cmd))) {   
   
        new JbpmSchema(JbpmSessionFactory.createConfiguration()).saveSqlScripts(args[1], args[2]);   
   
      }  

现在这段代码应该是这个样子:
    public static void main(String[] args) {   
   
   try {   
   
     if ( (args==null|| (args.length==0) ) {   
   
       throw new IllegalArgumentException();   
   
     }   
   
       
   
     String cmd = args[0];   
   
       
   
     if ("create".equalsIgnoreCase(cmd)) {   
  
       Configuration configuration = createConfiguration(args, 1);   
  
       new JbpmSchema(configuration).createSchema();   
  
     } else if ("drop".equalsIgnoreCase(cmd)) {   
  
       Configuration configuration = createConfiguration(args, 1);   
  
       new JbpmSchema(configuration).dropSchema();   
  
     } else if ("clean".equalsIgnoreCase(cmd)) {   
  
       Configuration configuration = createConfiguration(args, 1);   
  
       new JbpmSchema(configuration).cleanSchema();   
  
     } else if ("scripts".equalsIgnoreCase(cmd)) {   
  
       Configuration configuration = createConfiguration(args, 3);   
  
       new JbpmSchema(configuration).saveSqlScripts(args[1], args[2]);   
  
     } else if ((args != null&& (args.length > 3&& ("scripts".equalsIgnoreCase(cmd))) {   
  
       new JbpmSchema(JbpmSessionFactory.createConfiguration()).saveSqlScripts(args[1], args[2]);   
  
     }  

好了,现在一切都完美了。我们接下来执行最后一步,生成我们需要的脚本。

6. 打开命令行提示符窗口并在命令行中导航到子目录 jbpm-db,键入命令  ant oracle.scripts。等命令执行完毕以后,会发现在路径 jbpm-db"build"oracle"scripts 下生成了我们需要的脚本文件:
oracle.clean.sql
oracle.create.sql
oracle.drop.create.sql
oracle.drop.sql