最近要开始使用activiti结合原有的系统来开发一个专业领域内的业务管理软件,以下记录了第一次搭建该开发平台过程中所遇到的各种问题,备忘。
 

一、按照如下方式新建一个web工程

之所以要用maven,主要是为了解决各种依赖项的问题,用maven来管理依赖项还是很方便的。
 用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一般现在都是用3.0,在Project Facets里面修改Dynamic web module为3.0的时候就会出现Cannot change version of project facet Dynamic web module to 3.0,如图:
 
解决这个问题的步骤如下:
1. 把Servlet改成3.0,打开项目的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="schedule-console" version="3.0">
2. 修改项目的设置,在Navigator下打开项目.settings目录下的org.eclipse.jdt.core.prefs
把1.5改成1.8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
 
 
3. 打开org.eclipse.wst.common.project.facet.core.xml 
把java改为1.8, 把jst.web改为3.0;
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.8"/>
</faceted-project>
 
二、解决报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
可以使用如下步骤来解决。
1、右击web工程-》属性或Build Path-》Java Build Path->Libraries-> Add Libray...->Server Runtime -》Tomcat Server
2、切换到Java Build Path界面中的Orader and Export,选择Tomcat。
 
 
三、修改项目的pom.xml文件,添加activiti相关依赖项
相关依赖项如下:
 
  <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-engine</artifactId>
      <version>${activiti-version}</version>
    </dependency>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring</artifactId>
      <version>${activiti-version}</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.4.3</version>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>1.3.168</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.6</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.7.6</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>

</dependency>

 
其中activiti-version的定义如下:
  <properties>
    <activiti-version>5.18.0</activiti-version>

</properties>  

 
其实这些内容我都是从Activiti工程的pom文件中拷贝过来的。
 
四、添加activiti需要的配置文件
在activiti的userguide(http://activiti.org/userguide/index.html#_configuration )中有说。
如果我们使用如下语句来创建一个流程引擎实例
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()
 
那么实际上他是到该项目的classpath路径下去找一个名为 activiti.cfg.xml的配置文件,然后根据该配置文件的设置,通过spring的方式来创建一个processEngine。而且是去找其中的那个名字是default的processEngine。
所以我们可以在该项目的src/main/resources 目录下创建一个名为 activiti.cfg.xml的文件,然后将如下内容复制进去。
 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd">
 
    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">     
    </bean>

</beans>

 
五、创建sql server数据库
    通过sql server management studio 创建一个数据库,比如名字叫做 activiti    
    
六、在maven中添加sql server jdbc依赖项
    在maven仓库中是没有sql server 的jdbc jar包的,可以按照如下步骤操作

Download the JDBC driver for Microsoft SQL Server

    1. Visit the MSDN site for SQL Server and download the latest version of the JDBC driver for your operating system.
    2. Unzip the package
    3. Open a command prompt and switch into the expanded directory where the jar file is located.
    4. Execute the following command. Be sure to modify the jar file name and version as necessary:
1
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
    1. You should see something similar to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /Users/claude/installers/JDBC/sqljdbc_4.0/enu/sqljdbc4.jar to /Users/claude/.m2/repository/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.jar
[INFO] Installing /var/folders/c6/q1bdtq557kv54783p1g6cbsw0000gp/T/mvninstall1874482299687761721.pom to /Users/claude/.m2/repository/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.208s
[INFO] Finished at: Tue Mar 13 14:07:31 EDT 2012
[INFO] Final Memory: 3M/81M
[INFO] ------------------------------------------------------------------------

Modify your POM

Include the new dependency by modifying your project’s pom.xml. Add the following dependency:

1
2
3
4
5
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

Save the pom.xml file and build the project to make sure no errors exist.

七、让activiti连接sql server数据库
        修改第四节中的activiti.cfg.xml文件,将 processEngineConfiguration的内容改成下文这样:
    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
        <property name="databaseSchemaUpdate" value="true"/>
        <property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;databaseName=activiti2 " />
        <property name="jdbcDriver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
        <property name="jdbcUsername" value="sa" />
        <property name="jdbcPassword" value="sa123" />        

</bean>  

 
八、在代码中使用activiti的api    
              ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();    
            if(processEngine != null)
            {
                out.println("<h1> Hello !" + processEngine.getName() + "</h1>");
                IdentityService identityService = processEngine.getIdentityService();
                List<String> keys = identityService.getUserInfoKeys("Kermit");
                for(String key: keys)
                {                    
                    out.println(String.format("<h1> key = %s, value = %s </h1>", key, identityService.getUserInfo("Kermit", key)));
                }
            }   
    以上在调用 ProcessEngines.getDefaultProcessEngine();    的时候,实际上背后就会去调用搜索classPath目录下的activiti.cfg.xml文件,然后通过其中的配置来创建processEngine对象。
    
九、在eclipse中调试activiti项目

在eclipse中调试web项目,其实他是把相关的资料生成到如下路径:

<eclipse workspace dir>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MavenWeb

    如果发现某项配置修改之后,调试的时候没有生效,那可以试着clean一下,  Project ->clean...,然后重新生成即可。
 
 
 

Activiti系列: 如何在web中使用activiti和sql server的更多相关文章

  1. Activiti系列——如何在eclipse中安装 Activiti Designer插件

    这两天在评估jbpm和Activiti,需要安装一个Activiti Designer插件试用一下. 一.在线安装 从<Activiti实战>了解到可以通过如下方式安装 打开Eclipse ...

  2. 在英文版操作系统中安装的MS SQL server,中文字段无法匹配

    在英文版的操作系统中安装的MS SQL server,会出现中文字段无法被匹配到.其原因在于英文环境下安装的MS SQL server的排序规则不包括中文. 所以解决办法就是更改MS SQL serv ...

  3. 处于同一个域中的两台Sql server 实例无法连接

    处于同一个域中的两台Sql server 实例无法连接,报的错误信息如下: A network-related or instance-specific error occurred while es ...

  4. 如何在64位系统上安装SQL Server 2000

    如何在64位系统上安装SQL Server 2000? 现在用SQL Server 2000数据库的人少了吧?大都是SQL Server 2005/2008了.不过还是有需求的,今天一朋友就让我在他的 ...

  5. 处于同一域中的两台SQL Server 实例无法连接

    处于同一个域中的两台Sql server 实例无法连接,报的错误信息如下: A network-related or instance-specific error occurred while es ...

  6. Oracle中INSTR函数与SQL Server中CHARINDEX函数

    Oracle中INSTR函数与SQL Server中CHARINDEX函数 1.ORACLE中的INSTR INSTR函数格式:INSTR(源字符串, 目标字符串, 起始位置, 匹配序号) 说明:返回 ...

  7. 流程引擎Activiti系列:在eclipse中搭建咖啡兔的Activiti演示工程中的各种坑及其解决方法(kft-activiti-demo-no-maven)

    近期在学习activiti,打算基于现有的框架,比如activiti-explorer或者咖啡兔的示例工程 kft-activiti-demo,在此基础上添加自己的业务流程,看看是否可以走通,以及这个 ...

  8. .netcore中使用EFCore连接SQL Server并部署至Ubuntu

    前面一篇记录了如何在windows下开发asp.net core程序,并部署至ubuntu系统中.但仅仅是建立了一个demo项目,项目本身并没有实现多少功能.多数时候,我们的项目是要和数据库打交道.E ...

  9. Python web(Django)连接Sql server

    (开开心心每一天~ ---虫瘾师) Python Web(Django) 与SQL SERVRE的连接----Come QQ群:607021567(里面有很多开源代码和资料,并且python的游戏也有 ...

随机推荐

  1. CoreAnimation-03-隐式动画

    简介 每个UI控件,默认自动创建一个图层(根图层),即每个UI控件对应于至少一个图层 可以手动创建图层,这些图层为非根图层 对非根图层的某些属性(标记为Animatable的属性)进行修改,默认会自动 ...

  2. olacle数据库员工表的创建,及插入数据,添加约束,删除列,查询数据的sql语句

    ---删除原有的员工表drop TABLE employee;---创建员工表CREATE TABLE employee       (       empno NUMBER(4) NOT NULL, ...

  3. 烂泥:【解决】Ubuntu下使用SSH连接centos系统很慢

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 这几天在Ubuntu下使用SSH连接centos系统,发现连接很慢.建议一个连接大约需要30s.很是坑爹,如下: 后来查询相关资料,发现这个是Ubunt ...

  4. .NET三层架构例子超链接可以点击显示内容页面

    在研究了一个星期的三层架构写出的一个小功能,使用三层架构并实现点击新闻标题可以跳转到自己写的新闻页面. 首先是一个DBHelper,这个不是我自己写的,是朋友给我的 using System; usi ...

  5. UVA 10827 Maximum sum on a torus (LA)

    算法入门经典训练指南88页练习 ::这道题只要把原矩阵扩大4倍,那么其跟最大子矩阵的题目就很类似,把二维转化成一维,求最大的序列和,不过这个序列的长度不能超过n. 长度不能超过n? 那这道题又跟hdu ...

  6. R语言中数据框的横向合并与纵向合并

    #横向合并ID<-c(1,2,3,4)name<-c("Jim","Tony","Lisa","Tom")s ...

  7. 矩阵乘法快速幂 codevs 1732 Fibonacci数列 2

    1732 Fibonacci数列 2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 在“ ...

  8. Mybatis框架_part1

    mybatis介绍 mybatis就是一个封装了jdbc的持久层框架,它的前身是ibatis.Mybatis与hibernate一样都是持久层框架,但是它与hibernate不同的是,它不是一个完全的 ...

  9. 边工作边刷题:70天一遍leetcode: day 71-2

    One Edit Distance 要点:有两种解法要考虑:已知长度和未知长度(比如只给个iterator) 已知长度:最好不要用if/else在最外面分情况,而是loop在外,用err记录misma ...

  10. HDU 3600 Simple Puzzle 归并排序 N*N数码问题

    先介绍八数码问题: 我们首先从经典的八数码问题入手,即对于八数码问题的任意一个排列是否有解?有解的条件是什么? 我在网上搜了半天,找到一个十分简洁的结论.八数码问题原始状态如下: 1 2 3 4 5 ...