jbpm 项目实践 1.2 (集成appfuse spring modules)

阅读更多

 

 



安装配置appfuse jsf basic

下载 smtp server 安装 推荐  Personal Mail Server Pro v2.3    crsky 可以下载.  网上可以找到 Serial

由于没有找到特别好用的free smtp server  for  windows .

 

 

保持默认配置即可.

jbpm 项目实践 1.2 (集成appfuse spring modules)_第1张图片

 

 

 

进入eclipse  工程目录 方便以后直接导入

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace>
执行
mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-jsf -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=net.myjbpm.app -DartifactId=myapp


启动mysql  如果默认使用 root  空密码 则不需要修改. 否则修改 C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myjbpm\pom.xml文件

修改 文件底部

 
        org.dbunit.dataset.datatype.DefaultDataTypeFactory
        CLEAN_INSERT
        org.hibernate.dialect.MySQL5InnoDBDialect
        mysql
        mysql-connector-java
        5.0.5
        com.mysql.jdbc.Driver
       
        root
       


我习惯使用easymock  , 修改maven  dependency 可选.
.....

   
        
            org.easymock
            easymock
            ${easymock.version}
            test
       


....
   2.2
....


C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myjbpm>mvn

 

 

时间较长, 请煮杯咖啡, 慢慢品尝.

完成后


C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn jetty:run-war

 

 

 

jbpm 项目实践 1.2 (集成appfuse spring modules)_第2张图片

 

 

生成eclipse工程文件.确保本机smtp server启动

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn install eclipse:eclipse

 

推荐 不要运行展开, web  和 java 源码, 方便以后升级.  阅读源码可以新建一个工程查看源码

 

 

 

 

安装eclipse maven plugin 参考.

http://m2eclipse.codehaus.org/Installing_Maven_2.0_plugin_for_Eclipse.html

 

http://m2eclipse.codehaus.org/Maven_2.0_Plugin_for_Eclipse.html

 

 

 

配置 maven 环境 for eclipse.

 

 

 

jbpm 项目实践 1.2 (集成appfuse spring modules)_第3张图片

 

jbpm 项目实践 1.2 (集成appfuse spring modules)_第4张图片

 

 

 

 

 将myapp工程导入eclipse中.

 

修改 maven pom  新增 jbpm spring-modules dependency


 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\pom.xml

 

我以本机 repository server 方式 替换了 spring 官方的spring-modules-jbpm31-0.8a.pom

 

由于目前spring-modules支持 jbpm3.1 实际上可以通过修改一些配置支持jbpm3.2

 

添加本机repository server 声明

 

   
                   myRepository 
               http://localhost/m2/repository 
             
  

 

安装 apache 配置 repository server 还可以用其他工具, 网上有一些文章, 不再详述.

 

添加  dependency

 

 

 


       
            org.springmodules
            spring-modules-jbpm31
            0.8a
       



       
   
          org.jbpm
          jbpm-jpdl
         3.2
   

   
    
      org.jbpm
      jbpm-identity
     3.2
   

 

新增菜单.

 

修改C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\common\menu.jsp

新增

    
   

 

修改C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\WEB-INF\menu-config.xml

新增


        

 

 

编辑C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\resources\ApplicationResources_zh_CN.properties

新增

menu.task=我的任务
menu.process=流程管理 

 

 C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn jetty:run

 

http://localhost:8080    查看菜单已经增加.

 

 


集成 jbpm appfuse spring modules

 

jbpm  spring-modules-jbpm 相关依赖有一些问题, 查看pom 中相关配置.

 

新建文件

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\resources\jbpmApplicationContext.xml

 

主要包含spring-modlues 相关配置

 











	
		
		
		
		
	

	
		
		
			
				classpath*:org/jbpm/**/*.hbm.xml
			
		
		
			
				
					org.hibernate.dialect.MySQL5InnoDBDialect
				
				false
				true
				
					org.hibernate.cache.EhCacheProvider
				
			
		
	

	
	
		
	

	
	
		
		
		
			
				
				
			
		
		
	

	
	
		
	




	

	
	
		
		
	


 

修改 C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\WEB-INF\web.xml

 

添加jbpmApplicationContext.xml

 

  
    
        contextConfigLocation
        
            classpath:/applicationContext-resources.xml
            classpath:/applicationContext-dao.xml
            classpath:/applicationContext-service.xml
            classpath:/jbpmApplicationContext.xml
            classpath*:/applicationContext.xml
            /WEB-INF/applicationContext*.xml
            /WEB-INF/xfire-servlet.xml
            /WEB-INF/security.xml
        
    
 

 

 

 

 

 

 

创建dao test class

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\test\java\net\myjbpm\bpm\dao

 

package net.myjbpm.bpm.dao;

import java.util.List;

import org.jbpm.graph.def.ProcessDefinition;

public class JbpmDaoTest extends JbpmBaseDaoTestCase {

	private JbpmDao jbpmDao = null;

	public void setJbpmDao(JbpmDao jbpmDao) {
		this.jbpmDao = jbpmDao;
	}

	public void testGetProcessDefinitions() throws Exception {
		List processes = jbpmDao.getProcessDefinitions();
		assertTrue(processes.size() > 0);
	}

}
 

 

 

创建测试用jbpm 相关配置

新建C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\myapp\src\test\resources\jbpmApplicationContext.xml

 







	


	
		
		
		
		
	

	
		
		
			
				classpath*:org/jbpm/**/*.hbm.xml
			
		
		
			
				
					org.hibernate.dialect.MySQL5InnoDBDialect
				
				false
				true
				
					org.hibernate.cache.EhCacheProvider
				
			
		
	

	
	
		
	

	
	
		
		
		
			
				
				
			
		
		
		
	

	
	

	
	
		
	




	

	
	
		
		
	


 

 

参考http://forum.springframework.org/showthread.php?t=31795

 

 

 

 

创建相关实现 class , interface

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\java\net\myjbpm\bpm\dao

 

 

package net.myjbpm.bpm.dao;

import java.util.List;

import org.jbpm.graph.def.ProcessDefinition;



public interface JbpmDao {

	  /**
     * Gets a list of users ordered by the uppercase version of their processname.
     *
     * @return List populated list of users
     */ 
    List getProcessDefinitions();
	
}

 

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\java\net\myjbpm\bpm\dao\hibernate

 

package net.myjbpm.bpm.dao.hibernate;

import java.util.List;

import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
import org.jbpm.graph.def.ProcessDefinition;
import org.springmodules.workflow.jbpm31.JbpmCallback;
import org.springmodules.workflow.jbpm31.JbpmTemplate;

import net.myjbpm.bpm.dao.JbpmDao;

public class JbpmDaoHibernate implements JbpmDao{

	private JbpmTemplate jbpmTemplate;
	
	@SuppressWarnings("unchecked")
	public List getProcessDefinitions() {
				return (List) jbpmTemplate.execute(new JbpmCallback() {
					public Object doInJbpm(final JbpmContext jbpmContext)
							throws JbpmException {
						return jbpmContext.getGraphSession()
								.findLatestProcessDefinitions();
					}
				});

	}
	

	public JbpmTemplate getJbpmTemplate() {
		return jbpmTemplate;
	}

	public void setJbpmTemplate(JbpmTemplate jbpmTemplate) {
		this.jbpmTemplate = jbpmTemplate;
	}

}

 

 

配置 spring context

 


 

修改C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\WEB-INF\applicationContext.xml

 

 

 
    
    
        
    

    
    
      
        
    
 

 

启动mysql.

 

测试dao

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn test -Dtest=JbpmDaoTest

 

测试结果在C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\target\surefire-reports

 

创建 manager test class

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\test\java\net\myjbpm\bpm\service\impl

 

package net.myjbpm.bpm.service.impl;


import static org.easymock.EasyMock.*;

import java.util.ArrayList;
import java.util.List;

import net.myjbpm.bpm.dao.JbpmDao;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.jbpm.graph.def.ProcessDefinition;

import junit.framework.TestCase;
public class JbpmManagerImplTest  extends TestCase{
	  private final Log log = LogFactory.getLog(JbpmManagerImplTest.class);
	  
	  private JbpmManagerImpl manager = null;
	  private JbpmDao dao = null;
	  private ProcessDefinition process = null;
	  
	    protected void setUp() throws Exception {
	        log.debug("setUpDao for JbpmManageImplTest");
	        dao = createStrictMock(JbpmDao.class);
	        manager = new JbpmManagerImpl((JbpmDao) dao);
	    }
 
	
 
	    public void testGetProcesses() {
	        log.debug("testing getProcesses");

	        List processes = new ArrayList();

	        // set expected behavior on dao
	        expect(dao.getProcessDefinitions()).andReturn(processes);
	        replay(dao);

	        List result = manager.getProcessDefinitions();
	        assertSame(processes, result);
	        verify(dao);
	    }

	  

	  
	  
	

}

 

package net.myjbpm.bpm.service;

import java.util.List;

import org.jbpm.graph.def.ProcessDefinition;

public interface JbpmManager {
	
	 List getProcessDefinitions();

}

 

 

 

package net.myjbpm.bpm.service.impl;

import java.util.List;

import org.jbpm.graph.def.ProcessDefinition;

import net.myjbpm.bpm.dao.JbpmDao;
import net.myjbpm.bpm.service.JbpmManager;

public class JbpmManagerImpl implements JbpmManager{

	 private JbpmDao jbpmDao;
	 
	
	
	public JbpmManagerImpl() {
		super();
		// TODO Auto-generated constructor stub
	}

	public JbpmManagerImpl(JbpmDao jbpmDao) {
		this.jbpmDao = jbpmDao;
		// TODO Auto-generated constructor stub
	}

	public List getProcessDefinitions() {
		// TODO Auto-generated method stub
		return jbpmDao.getProcessDefinitions();
	}

	public JbpmDao getJbpmDao() {
		return jbpmDao;
	}

	public void setJbpmDao(JbpmDao jbpmDao) {
		this.jbpmDao = jbpmDao;
	}

}
 

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn test -Dtest=JbpmManagerImplTest

 

创建action test class

 

package net.myjbpm.bpm.webapp.action;


import net.myjbpm.bpm.service.JbpmManager;

public class ProcessListTest extends JbpmBasePageTestCase {

	private ProcessList bean;
	private JbpmManager jbpmManager;

	public void setJbpmManager(JbpmManager jbpmManager) {
		this.jbpmManager = jbpmManager;
	}

	@Override
	@SuppressWarnings("unchecked")
	protected void onSetUp() throws Exception {
		super.onSetUp();
		bean = new ProcessList();
		bean.setJbpmManager(jbpmManager);

		// add a test process to the database @do it latter@

	}

	@Override
	protected void onTearDown() throws Exception {
		super.onTearDown();
		bean = null;
	}

	public void testGetProcesses() throws Exception {
		assertTrue(bean.getProcesses().size() >= 1);
		assertFalse(bean.hasErrors());
	}

}
 

 

 

 

 

 

实现类

 

 

package net.myjbpm.bpm.webapp.action;

import java.io.Serializable;
import java.util.List;

import net.myjbpm.bpm.service.JbpmManager;

import org.appfuse.webapp.action.BasePage;

public class ProcessList extends BasePage implements Serializable{

	 /**
	 * 
	 */
	private static final long serialVersionUID = 5941146729015089028L;
	private JbpmManager jbpmManager;
	
	  public ProcessList() {
	        setSortColumn("name");
	    }
	    
	    @SuppressWarnings("unchecked")
		public List getProcesses() {
	    	
	        return sort(jbpmManager.getProcessDefinitions());
	    }

		public JbpmManager getJbpmManager() {
			return jbpmManager;
		}

		public void setJbpmManager(JbpmManager jbpmManager) {
			this.jbpmManager = jbpmManager;
		}
}
 

 

配置 jsf  manage bean

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\WEB-INF\faces-config.xml

 

 

  
    
     
        processList
        net.myjbpm.bpm.webapp.action.ProcessList
        request
        
            jbpmManager
            #{jbpmManager}
        
    
 

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn test -Dtest=ProcessListTest

 

 

jsf  xhtml 文件.

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp\src\main\webapp\bpm\process.xhtml

 






    #{text['processList.title']}
    
    








    
        
            
                
            
        
      	
    
    
      
        
            
                
            
        
        
      
    
    
    
        
            
                
            
        
      
    
   
  



     






 

添加相关资源文件. properites.

 

C:\eclipse-SDK-3.3.1.1-win32\eclipse\workspace\myapp>mvn jetty:run-war

 

 

 

 

jbpm 项目实践 1.2 (集成appfuse spring modules)_第5张图片

 

 

 

安装eclipse 插件. 

下载 jbpm-jpdl-suite-3.2.GA.zip 包含了 designer.

在eclipse 安装文件夹下D:\eclipse-SDK-3.3.1.1-win32\eclipse\links

新建一个 jpbm32.link

内容为

 

path=D:\\software\\jbpm-jpdl-3.2.GA\\designer

 

jbpm 项目实践 1.2 (集成appfuse spring modules)_第6张图片

 

jbpm-jpdl-designer-3.1.2  加入了一些的有用的特性,  例生成jsf orms.xml   重新配置eclipse link 文件

删除 jbpm32.link

在eclipse 安装文件夹下D:\eclipse-SDK-3.3.1.1-win32\eclipse\links\jbpm32.link

 

新建D:\eclipse-SDK-3.3.1.1-win32\eclipse\links\jbpm-jpdl-designer-3.1.2.link

 

path=D:\\eclipse-SDK-3.3.1.1-win32\\plugin\\jbpm-jpdl-designer-3.1.2

 


http://labs.jboss.com/jbossjbpm/downloads/




完成时间预计 2008年1月12日 

实际完成时间 2008年1月17日

 

LOOKING FORWORDS :

开发任务管理相关模块.

开发常用流程实例.

 

THAT'S ALL

 

  • repository.rar (623.8 KB)
  • 描述: 自己的apache maven 仓库放了3个jar 文件.
  • 下载次数: 220
  • myapp.rar (95.1 KB)
  • 下载次数: 194

你可能感兴趣的:(Appfuse,JBPM,Spring,项目管理,Eclipse)