Small steps with big feet
jBPM4 Hello World
Update 1 feb 2010: hello world update for jBPM 4.3
As promised in my previous post, I’ll show you how easy it is to start using the new jBPM4 API.
I’ll use the mother of all demo’s and implement a process that prints ‘Hello World’ to the screen. One of the core strengths of jBPM has always been the embeddability in several environments (SE, Spring, EJB, etc), so today I’ll show how to create a SE application that uses jBPM as a regular library. I’m going to do the demo with the CR1 release, but the example should be quite protable to the 4.0GA release.
Download the (Maven) example here.
If you want to do it yourself, follow these steps:
- (non-Maven users): download the distribution and unzip it somewhere
- (non-Maven users): in Eclipse, add jbpm.jar the lib folder of the unzipped distribution to the project classpath.
(maven-users): create an empty maven project and add the following dependency to your pom.xml:
<dependency> <groupId>org.jbpm.jbpm4</groupId> <artifactId>jbpm-jpdl</artifactId> <version>4.0.CR1</version> </dependency>
- Now we’ll create the ‘logic’ of our process. Create a class called Printer :
package be.jorambarrez.jbpm4.helloworld;
public class Printer {
public void printHelloWorld() {
System.out.println("<---------------->");
System.out.println(" HELLO WORLD!");
System.out.println("<---------------->");
}
}
- Create the HelloWorld process. The process uses a Java activity here to call the ‘printHelloWorld’ method on our ‘business logic’.
<process name="helloWorld" xmlns="http://jbpm.org/4.0/jpdl"> <start> <transition to="printHelloWorld"/> </start> <java class="be.jorambarrez.jbpm4.helloworld.Printer" method="printHelloWorld" name="printHelloWorld"> <transition to="theEnd"/> </java> <end name="theEnd" /> </process>
which looks like this if you have installed the GPD:

For JPDL4, one of the main goals is process readability. If you take a look at this process or any of the shipped example processes, you’ll notice that this has worked out quite fine.
- Create a minimal jBPM config (jbpm.cfg.xml)
<jbpm-configuration> <import resource="jbpm.default.cfg.xml"/> <import resource="jbpm.tx.hibernate.cfg.xml"/> <import resource="jbpm.jpdl.cfg.xml"/> </jbpm-configuration>
The imports shown here contain a default configuration. If needed, you can remove the imports and configure jBPM for your own environment.
- Create a basic Hibernate config called jbpm.hibernate.cfg.xml(I’m using HSQLDB, but any DB supported by Hibernate will do):
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <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:.</property> <property name="hibernate.connection.username">sa</property> <property name="hibernate.connection.password"></property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">create-drop</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.jpdl.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
Note: if you are using 4.0GA (instead of CR1), remove the ‘jbpm.jpdl.hbm.xml’ line from the hibernate mapping.
and add the correct driver to your classpath. With Maven and HSQLDB, add this dependency to your pom.xml.
<dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>1.8.0.7</version> </dependency>
- Finally, create a main method which constructs the ProcessEngine
ProcessEngine processEngine = new Configuration().setResource("my.jbpm.cfg.xml").buildProcessEngine();
and retrieve the needed services:
RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService = processEngine.getExecutionService();
which we can use to deploy our hello world process and start a process instance
repositoryService.createDeployment()
.addResourceFromClasspath("hello_world.jpdl.xml")
.deploy();
executionService.startProcessInstanceByKey("helloWorld");
After the Hibernate loading, you’ll see the Hello World message from the Printer class.
That’s it, your very first jBPM4 Hello World process. With this setup, you can start playing with the different activities or change the configuration. Do note how easy it is to embed this code into other environments (Spring, EJB, …) due to the fact that jBPM is ‘just another Java library’. Although the hello world process is extremely simple, all the setup around it (jBPM and Hibernate config) are exactly the same as for any arbitrary complex process.
Stay tuned for more posts about jBPM4!
Nice HelloWorld,
this is a good ‘getting started’. It is necesary because the oficial doc lacks of this kind of doc.
Thank you very much.
Angel, the examples of the jBPM distribution contain a similar ‘hello world’ process.
Just run the demo.setup with ant and you’re all set to go!
Hi ,
Hi ,
I am new to JBPM and need some help .
In the devguide document it was mentioned as
“To execute processes without persistence, the client API can be used to work with process and execution objects directly. The client API expose the methods of the core model objects.” .
We are in need of creating and running a process without persistence .
I tried going throught the client API javadocs and was not able to figure out a way to create and execute a process .
Can you point me out the proper direction to look for the samples / documents regarding this.
Hi Jorram,
Neat stuff, really! Thanks a bunch. Great help for newbies like me. I’m facing a small problem though.
I’ve used the above maven example with the new jbpm4 release. I’ve had to add a dependency for javax.mail and hibernate in the pom. There’s some activity writing in the db and after which it throws the following error:
org.jbpm.pvm.internal.wire.WireException: couldn’t initialize object ‘org.jbpm.pvm.internal.repository.RepositorySessionImpl’: proxy class not found: org.jbpm.jpdl.internal.model.JpdlExecution
at org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor.initialize(ObjectDescriptor.java:233)
at org.jbpm.pvm.internal.wire.WireContext.performInitialization(WireContext.java:537)
at org.jbpm.pvm.internal.wire.WireContext.initialize(WireContext.java:499)
…..
Any pointers? Thanks
Anand, try to remove the jbpm.jpdl.hbm.xml from the Hibernate mapping. The JpdlExecution class has been removed for 4.0 GA.
thirumal, for the moment the API doesn’t work completely without persistence yet.
If you use the lower-level PVM API, you can do it without persistence (but then you don’t have the goodies from JPDL).
Memory execution is definitely on our agenda to tackle in one of the next releases!
Hi Jorram,
Awesome! Worked like a charm! Now that the Hello-World works, guess I need to start figuring out how it all ties together in JBPM4. Again, thanks a bunch!
Hello,
Your example would be perfect if you continue and explain how to deploy / execute the hello world process…
@yoprogramo
In fact, the process is already deployed (deploying = parse it and store it in the database).
Any other jBPM process engine instance can now use it by pointing its hibernate.cfg.xml to the same database. If you’ve done that, you only need to call executionService.startProcessInstanceByKey(“helloWorld”);
Another example could be to deploy the example to the database of the jBPM console and start it through there.
I have followed all the instructions. My repositoryService instance is null when I run the test program. Please help.
Try to userforum, which is an easier medium to discuss your problem: http://www.jboss.org/index.html?module=bb&op=viewforum&f=217
i have error any one plz help
Exception in thread “main” org.jbpm.api.JbpmException:
error: couldn’t parse xml document : org.jbpm.api.JbpmException: resource my.jbpm.cfg.xml does not exist
at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:168)
at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:141)
at org.jbpm.pvm.internal.xml.Parse.checkErrors(Parse.java:189)
at org.jbpm.pvm.internal.cfg.JbpmConfiguration.parse(JbpmConfiguration.java:165)
at org.jbpm.pvm.internal.cfg.JbpmConfiguration.setResource(JbpmConfiguration.java:137)
at org.jbpm.api.Configuration.setResource(Configuration.java:106)
at be.jorambarrez.jbpm4.helloworld.Main.main(Main.java:13)
Caused by: org.jbpm.api.JbpmException
at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:164)
… 6 more
Caused by: org.jbpm.api.JbpmException: resource my.jbpm.cfg.xml does not exist
at org.jbpm.pvm.internal.stream.ResourceStreamInput.openStream(ResourceStreamInput.java:55)
at org.jbpm.pvm.internal.xml.Parse.getInputSource(Parse.java:145)
at org.jbpm.pvm.internal.xml.Parser.buildDom(Parser.java:450)
at org.jbpm.pvm.internal.xml.Parser.execute(Parser.java:387)
at org.jbpm.pvm.internal.xml.Parse.execute(Parse.java:157)
… 4 more
thank you
@OptixPro: the error is quite descriptive: there is no my.jbpm.cfg.xml on your classpath.
I am trying this example in Eclipse. I put the main method in the Printer.java file and get this error:
java.lang.NoClassDefFoundError: com/memc/jbpm4/helloworld/Printer
Caused by: java.lang.ClassNotFoundException: com.memc.jbpm4.helloworld.Printer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread “main”
Where do you put the main method mentioned? Is it in the Printer.java file?
Also, do you have any more examples on setting up and using jbpm for 1st time users?
Thanks and I hope you can help as we would really like to use jbpm at our company.
Great Post! Thanks!
for maven-users please add to your pom.xml:
jboss
http://repository.jboss.com/maven2
this made us mad us the very first time with jbpm & maven!
{code} xml
repositories
repository
id=jboss
url=http://repository.jboss.com/maven2
/repository
/repositories
{code} xml
Hi
Thanks for the post..
My concern is i have created process archive i.e. OrderProcess.jpdl ( ref. user document). This has process.jpdl.xml files with supporting classes.
Now I want to get them using JNDI lookup.
Can you please let me know where to mention “OrderProcess.jpdl” in order to get processes by their ids or keys
Hi,
Thanks a lot for this nice example.Currently we are using jBPM 3.2.2 with DB2 in our project . Now we are in analysis phase to migrate it to jBPM 4.0.
But I could not found the DB script of DB2 UDB in any of the jBPM4 version. can you please let me know, if jBPM4 still support DB2? IF yes, how can I create those jBPM4_xxx tables.
Thanking you in advance, for your kind response.
@Prajatna: a DB2 script isnt in out distro because we haven’t set up QA for it yet (but it is planned for the near future). So basically there is no ‘official’ support. But since jBPM uses Hibernate under the hood, all should work without problems.
You can generate the DB2 specific schema by issuing a Hibernate hbbm2ddl command (check our build scripts for a concrete ant task you can use)
Thank you. It has been a great help.
Hi everybody
I have a problem when i try to execute the example:
Exception in thread “main” java.lang.NullPointerException
at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:89)
at
Is anyone that explain me this kind of problem?
Thank you very much
Hi Jorram,
Thanks for the wonderful post. When I try to run the Main.java( I am wrapping it as a servlet) I get this following exception..please can you help me..?
org.jbpm.api.JbpmException: couldn’t instantiate configuration of type org.jbpm.pvm.internal.cfg.ProcessEngineImpl
org.jbpm.api.Configuration.instantiate(Configuration.java:92)
org.jbpm.api.Configuration.(Configuration.java:62)
org.jbpm.api.Configuration.(Configuration.java:51)
be.jorambarrez.jbpm4.helloworld.Main.doGet(Main.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.ClassCastException: org.jbpm.pvm.internal.cfg.ProcessEngineImpl cannot be cast to org.jbpm.api.Configuration
org.jbpm.api.Configuration.instantiate(Configuration.java:90)
org.jbpm.api.Configuration.(Configuration.java:62)
org.jbpm.api.Configuration.(Configuration.java:51)
be.jorambarrez.jbpm4.helloworld.Main.doGet(Main.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
I have same issue as Roberto – NullPointerException deep within deploy().
Here is my main() method:
public static void main(String[] args)
{
log.info(“BEGIN”);
try{
log.info(“Loading JBPM configuration”);
ProcessEngine engine= new Configuration().setResource(“jbpm.cfg.xml”).buildProcessEngine();
RepositoryService repo= engine.getRepositoryService();
ExecutionService exec= engine.getExecutionService();
log.info(“Deploying process”);
repo.createDeployment().addResourceFromClasspath(“hello-world.jpdl.xml”).deploy();
log.info(“Starting process”);
exec.startProcessInstanceByKey(“helloWorld”);
log.info(“COMPLETE”);
}catch(Exception e){
e.printStackTrace(System.err);
}finally{
log.info(“FINALLY”);
}
log.info(“END”);
}// main
Here is the stack trace and last few lines of my log file:
INFO: Deploying process
Nov 16, 2009 5:10:08 PM org.jbpm.internal.log.Jdk14Log info
INFO: exception while executing command org.jbpm.pvm.internal.cmd.DeployCmd@15c998a
java.lang.NullPointerException
at org.jbpm.pvm.internal.repository.RepositorySessionImpl.deploy(RepositorySessionImpl.java:61)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:47)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:33)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:91)
at com.mydomain.omega.jbpm.example.HelloWorldApp.main(HelloWorldApp.java:30)
java.lang.NullPointerException
at org.jbpm.pvm.internal.repository.RepositorySessionImpl.deploy(RepositorySessionImpl.java:61)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:47)
at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:33)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:91)
at com.mydomain.omega.jbpm.example.HelloWorldApp.main(HelloWorldApp.java:30)
An additional note to my stack trace above, I’m using JBPM 4.2 inside Netbeans 6.7.
Please do give more info about the transient variables in jbpm4.2. i just want to know how to make the variables not to be persisted.hope ill get the replies with a good examples. thank you.
@Joe: looks like a configuration error. What is your jbpm.cfg.xml?
@Anonymous: I’ve found your questions at 4 different places already (my about page, Tom’s blog, etc.). Spamming is NOT the way yo get our attention. Transient variables are planned for a next release, we have the Jira publicly available for this cause.
Hi… I have a little problem while executing the examples that are present with jbpm4.0
org.jbpm.pvm.internal.wire.WireException: couldn’t initialize object ‘org.jbpm.pvm.internal.repository.RepositorySessionImpl’: Could not parse configuration: jbpm.hibernate.cfg.xml
hi ..
i have been facing this problem from last two days….but still i could not solve this problem …..Please help in this problem
While i am deploying the files i am getting the error like
org.hibernate.exception.GenericJDBCException: could not insert: [org.jbpm.pvm.internal.lob.Lob]
Help in solving this problem ……
hi …..
i have been facing the problem with jbpm4.0 + jboss 5.0 + jdk 1.6
required help to solve this
…..
Dec 16, 2009 5:38:31 PM org.jbpm.internal.log.Jdk14Log info
[jbpm-deploy] INFO: exception while executing command org.jbpm.pvm.internal.cmd.DeployCmd@d3c69c
[jbpm-deploy] java.lang.NullPointerException
[jbpm-deploy] at org.jbpm.pvm.internal.repository.RepositorySessionImpl.deploy(RepositorySessionImpl.java:55)
[jbpm-deploy] at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:46)
[jbpm-deploy] at org.jbpm.pvm.internal.cmd.DeployCmd.execute(DeployCmd.java:32)
[jbpm-deploy] at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
[jbpm-deploy] at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
[jbpm-deploy] at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
[jbpm-deploy] at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
[jbpm-deploy] at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:89)
[jbpm-deploy] at org.jbpm.pvm.internal.ant.JbpmDeployTask.deployFile(JbpmDeployTask.java:110)
[jbpm-deploy] at org.jbpm.pvm.internal.ant.JbpmDeployTask.execute(JbpmDeployTask.java:60)
[jbpm-deploy] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[jbpm-deploy] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[jbpm-deploy] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[jbpm-deploy] at java.lang.reflect.Method.invoke(Method.java:597)
[jbpm-deploy] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[jbpm-deploy] at org.apache.tools.ant.Task.perform(Task.java:348)
[jbpm-deploy] at org.apache.tools.ant.Target.execute(Target.java:357)
[jbpm-deploy] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[jbpm-deploy] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[jbpm-deploy] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[jbpm-deploy] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[jbpm-deploy] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[jbpm-deploy] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[jbpm-deploy] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[jbpm-deploy] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
@Anand: the error is quite obvious, there is something wrong with your jbpm.hibernate.cfg.xml config.
@Tifr: No clue without a stacktrace, environment, etc. These kind of questions are better asked on the user forum, since they will benefit other users too.
@Anonymous: Try to use the latest version (4.2, very soon 4.3). A lot of things have changed in the meanwhile.
Hi Joram ,
I want to install Jbpm Console(4.1) in Weblogic 10.3 .
Do you any links (or) doc which explains me in details how ti install JBPM in Weblogic ? as Ant build file lacks task for weblogic .
Thanks a lot, helped me to quickly use the processing engine! Now only if this was included in the official JBoss documentation.
Great Tutorial. I got the head start.