Tuesday, March 08, 2011

jBPM5 lightweight? Running on Android!

I recently bought myself a new Android phone, and as a developer, that obviously means I have to try and write my own application for it ! :)

And since we always claim jBPM is such a lightweight engine that you can embed it practically anywhere, I decided to give that a try: run the jBPM5 engine on Android. Some people might be thinking, why would I want to do that? Well, my primary goal was just as a proof of concept. But maybe, if we extend that proof of concept a little more and add more Android tasks, end users without any real development experience might be able to use it do model simple Android applications as well, who knows!

So after downloading the Eclipse tooling and following a hello world example, I decided to create a simple process that first asks the user for some keyword and then uses this keyword to search the jBPM community forum for entries containing that keyword (I know, not rocket science, you don't really need a workflow engine for that but it's just a demo example).


After adding the jBPM5 jars to the classpath, I updated my application to start this process when the application is started. I also created two domain-specific services for Android, one for requesting some input from the user (where I then bind this result to a process variable) and one for showing a web page (which shows a URL, which I created based on the input of the user).

And it worked almost[*] out of the box! So this is what it looks like (on the emulator, but it runs nicely on my phone as well). First you start the jBPM application ...



The first node in the process will ask you for a keyword you want to search for ...


And the last node will show the results of the query on the jBPM community forum in a browser ...


I'm pretty sure there are a lot of developers out there that try to play with new technologies like this, so if you're interested in playing with this and maybe extending this a little, let me know. Imagine we add a few more default services for showing an image, getting some file, getting GPS location, etc. Would be pretty cool if you could create more advanced applications like that.

I've uploaded the source code and the jbpm-android.apk so you can give it a try yourself !

[*] A small modification is needed in org.drools.util.CompositeClassLoader. Apparently, the Android JVM doesn't allow null as the parent classloader so I changed that to super(CompositeClassLoader.class.getClassLoader()) in the constructor, and that works fine.

7 comments:

  1. Hello, thank you for this article.
    I try to do the same thing but with a process on a xml file.
    It doesn't work. have you try to do this ?

    ReplyDelete
  2. Awesome! Big Kudos!

    Any Chance you'd want to try to get Drools running on Android if you had some help? :-)

    -matt

    ReplyDelete
  3. So this works great-- but a question: when I attempt to load a .bmpn file instead of defining the process programatically, I start getting errors which sure sound a lot like those experienced by Abhay in http://tech-voyage.blogspot.com/2011/06/getting-rule-engine-to-work-on-mobile.html

    Specifically, the line
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    dies with the following error at runtime:
    java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'

    Is there any other way to load a bpmn file (I used the Evaluation.bpmn from the jbpm samples) other than using KnowledgeBuilder?

    ReplyDelete
  4. Good article, thanks! A couple of questions:

    1. Have you ever been able to get this to work with an external BPMN file? I keep getting parser errors when I try.

    2. How did you get from the diagram (in your blog post) to the code (in your sample). Is there a code generation technique I'm missing, or was this hand coded?

    Thanks in advance.

    -Simon

    ReplyDelete
  5. I also created two domain-specific services for Android, one for requesting some input from the user (where I then bind this result to a process variable) and one for showing a web page (which shows a URL, which I created based on the input of the user). money making apps

    ReplyDelete