{"id":743,"date":"2010-05-14T23:45:25","date_gmt":"2010-05-14T18:15:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=743"},"modified":"2016-12-19T15:29:20","modified_gmt":"2016-12-19T09:59:20","slug":"embedding-jbpm-4-3-in-a-grails-1-2-2-application","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/embedding-jbpm-4-3-in-a-grails-1-2-2-application\/","title":{"rendered":"Embedding JBPM 4.3 in a Grails 1.2.2 Application"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In one of our projects, we had a requirement for using some existing Business Process Management tool. JBPM is one such tool that we are evaluating.<\/p>\n<p>Our first step was to run a &#8220;Hello World&#8221; process from inside the grails application. On searching over the internet, I didn&#8217;t find any helpful article\/blog on integrating JBPM inside a grails application. However, there were some very good resources on integrating JBPM with a spring application. I found <a href=\"http:\/\/www.jorambarrez.be\/blog\/2009\/07\/01\/jbpm4-hello-world\/\">Joram Barrez&#8217;s Hello World Example<\/a> very helpful and was able to integrate using the following steps:<\/p>\n<ol>\n<li>Download jbpm from <a href=\"http:\/\/sourceforge.net\/projects\/jbpm\/files\/\" target=\"_blank\">here.<\/a><\/li>\n<li>Unzip the contents and copy the jbpm.jar file to the lib directory of your application.\u00a0 The exploded directory has the following files\/ folders for version 4.3 : <a href=\"\/blog\/wp-ttn-blog\/uploads\/2010\/05\/Screenshot-1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1103\" title=\"JBPM Exploded Directory\" src=\"\/blog\/wp-ttn-blog\/uploads\/2010\/05\/Screenshot-1.png\" alt=\"\" width=\"655\" height=\"432\" \/><\/a><\/li>\n<li>Also copy the mail.jar from the jbpm installation directory (${jbpmHome}\/lib) to the lib directory of your application.<\/li>\n<li> Create a process descriptor file in the conf directory (helloWorld.jpdl.xml) with the following code<br \/>\n<blockquote>\n<pre lang=\"xml\">\r\n     <process name=\"helloWorld\" xmlns=\"http:\/\/jbpm.org\/4.0\/jpdl\">\r\n     <start>\r\n     <transition to=\"printHelloWorld\"\/>\r\n     <\/start>\r\n     \r\n     <java class=\"com.jbpm.example.Printer\" method=\"printHelloWorld\" name=\"printHelloWorld\">\r\n          <transition to=\"CheckDate\"\/>\r\n          <transition to=\"theEnd\"\/>\r\n     <\/java>\r\n     \r\n     <end name=\"theEnd\" \/>\r\n     <state name=\"CheckDate\">\r\n     <transition to=\"printHelloWorld\"\/>\r\n     <\/state>\r\n    <\/process> \r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li> Create a class in src\/groovy<br \/>\n<blockquote>\n<pre lang=\"groovy\">package com.jbpm.example\r\n\r\nclass Printer {\r\n\r\n public void printHelloWorld() {\r\n   System.out.println(\"&lt;----------------&gt;\");\r\n   System.out.println(\"&amp;nbsp;&amp;nbsp; HELLO WORLD!\");\r\n   System.out.println(\"&lt;----------------&gt;\");\r\n }\r\n}\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Create a minimal jBPM config (jbpm.cfg.xml) in the conf directory<br \/>\n<blockquote>\n<pre lang=\"xml\">\r\n     <jbpm-configuration>\r\n     <import resource=\"jbpm.default.cfg.xml\"\/>\r\n     <import resource=\"jbpm.tx.hibernate.cfg.xml\"\/>\r\n     <import resource=\"jbpm.jpdl.cfg.xml\"\/>\r\n    <\/jbpm-configuration>\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Create a basic Hibernate config called conf\/jbpm.hibernate.cfg.xml(I\u2019m using MySql, Still looking for a way on how to use the grails DataSource)<br \/>\n<blockquote>\n<pre lang=\"xml\">\r\n    <?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n    <!DOCTYPE hibernate-configuration PUBLIC\r\n    \"-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN\"\r\n    \"http:\/\/hibernate.sourceforge.net\/hibernate-configuration-3.0.dtd\">\r\n    <hibernate-configuration>\r\n     <session-factory>\r\n     <property name=\"hibernate.dialect\">org.hibernate.dialect.MySQL5InnoDBDialect<\/property>\r\n     <property name=\"hibernate.connection.driver_class\">com.mysql.jdbc.Driver<\/property>\r\n     <property name=\"hibernate.connection.url\">jdbc:mysql:\/\/localhost:3306\/testJbpm?autoReconnect=true<\/property>\r\n     <property name=\"hibernate.connection.username\">username<\/property>\r\n     <property name=\"hibernate.connection.password\">password<\/property>\r\n     \r\n     <property name=\"hibernate.format_sql\">true<\/property>\r\n     <property name=\"hibernate.hbm2ddl.auto\">update<\/property>\r\n     \r\n     <mapping resource=\"jbpm.repository.hbm.xml\" \/>\r\n     <mapping resource=\"jbpm.execution.hbm.xml\" \/>\r\n     <mapping resource=\"jbpm.history.hbm.xml\" \/>\r\n     <mapping resource=\"jbpm.task.hbm.xml\" \/>\r\n     <mapping resource=\"jbpm.identity.hbm.xml\" \/>\r\n     \r\n     <\/session-factory>\r\n    <\/hibernate-configuration>\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Create the following Spring beans is resources.groovy<br \/>\n<blockquote>\n<pre lang=\"groovy\">    \r\nspringHelper(org.jbpm.pvm.internal.processengine.SpringHelper) {\r\n        jbpmCfg = \"jbpm.cfg.xml\"\r\n}\r\nprocessEngine(springHelper:\"createProcessEngine\")\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Now lets deploy this process. To deploy a process we will need to inject the processEngine bean<br \/>\n<blockquote>\n<pre lang=\"groovy\"> def processEngine;<\/pre>\n<\/blockquote>\n<p>The code to deploy this process is<\/p>\n<blockquote>\n<pre lang=\"groovy\">RepositoryService repositoryService = processEngine.getRepositoryService();\r\n         repositoryService.createDeployment()\r\n                 .addResourceFromClasspath(\"helloWorld.jpdl.xml\")\r\n                 .deploy();\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Lets start an instance of this service :<br \/>\n<blockquote>\n<pre lang=\"groovy\">ExecutionService executionService = processEngine.getExecutionService();\r\nexecutionService.startProcessInstanceByKey(\"helloWorld\");<\/pre>\n<\/blockquote>\n<p>This will execute the printHelloWorld method of the Printer class as configured in the process description file.<\/li>\n<\/ol>\n<p>Hope you find this useful. We are still working on executing more complex processes and will keep posting our learnings.<\/p>\n<p>Your feedback and  suggestions are welcome.<\/p>\n<p>Regards<br \/>\n~~Himanshu Seth~~<\/p>\n<p>http:\/\/www.tothenew.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In one of our projects, we had a requirement for using some existing Business Process Management tool. JBPM is one such tool that we are evaluating. Our first step was to run a &#8220;Hello World&#8221; process from inside the grails application. On searching over the internet, I didn&#8217;t find any helpful article\/blog on integrating [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[7],"tags":[4840,240],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/743"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=743"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/743\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}