Question

According to the whitepaper on the jBPM page [1], jBMP can be easily used in a standalone app. However I could not find any information about how to actually do this. I want to create a simple java app (maybe with SWT), which displays a process with jBPM. The user should then be able to modify the applications behavior, by modifying the jBPM diagram. For this purpose I also have to integrate some eclipse components I think.. any ideas how this works?

[1] http://www.jboss.com/pdf/jbpm_whitepaper.pdf

Was it helpful?

Solution

Before you start, you may want also to see if Roamflow meets your needs as it seems to be a standalone jBPM Eclipse/RCP based viewer/editor.

Otherwise you should know how to build eclipse plug-ins, or get the book I found useful for most eclipse plugin/SWT development needs, "Eclipse Building Commercial-Quality Plug-ins", published by eclipse and Addison-Wesley. Also, I am not going to sit down and write you a test app, you need to understand the fundamentals anyhow.

  1. By stand alone they mean run in any old JVM with the right libraries. It does need to be deployed in a J2EE container, viewed through the web, etc.

  2. Look at the source code for the jBPM eclipse plug-in as it has the features you are looking for right? An SWT/eclipse based to that displays jBPM. This includes checking for extension points that jBPM may install which you can use to build your eclipse plug-in with quickly. For example: The jBPM editor code, here. Or how to serialize, here, re-use.

  3. Here is the critical SWT/drawing, a critical line is converting the jBPM into and SWT thing "g = new SWTGraphics(gc);". This seems to generate an image from a jBPM model.

    protected void writeImage() {           
    SWTGraphics g = null;
    GC gc = null;
    Image image = null;
    LayerManager lm = (LayerManager)getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
    IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
    
    try {
        Rectangle r = figure.getBounds();
        image = new Image(Display.getDefault(), r.width, r.height);
        gc = new GC(image);
        g = new SWTGraphics(gc);
        g.translate(r.x * -1, r.y * -1);
        figure.paint(g);
        ImageLoader imageLoader = new ImageLoader();
        imageLoader.data = new ImageData[] {image.getImageData()};
        imageLoader.save(getImageSavePath(), SWT.IMAGE_JPEG);
        refreshProcessFolder();
    
    } finally {
        //SNIP
    }
    }
    
  4. Learn from the plug-in's plugin.xml, src located here in this case. For example, here is the jBPM adding it's view to eclipse:

    point="org.eclipse.ui.views" ... view class="org.jboss.tools.flow.jpdl4.view.DetailsView"...
    

    This may be one extension you want to copy as it seems to stand up the "view". This will help you understand how they construct the pieces of their eclipse based app. You can search for these classes in your work space and view the source code if you installed the developer versions on the JBPM plug-ins.

  5. Decide if you need to hack apart the app parts built as GMF (Graphical Modeling Framework) stuff, like the model, behavior of the view/diagram and the different edit/drawing parts. Don't mess with this unless you have too. However, understanding GMF plug-ins or looking that the examples will help you understand what jBPM plug-in pieces you might need to use, especially if editing is needed.

  6. Roll the pieces into a plug-in, remembering to reuse what pieces (plugins/pluglets) you can from the jBPM project. May sure to build your eclipse plugin as an RCP or Rich Client... (Note jBPM does not currently have a RCP, per post) so that it can as a eclipse standalone application for easier deployment to people who do not have eclipse tool knowledge.

Let me know if this gets you headed down the correct path.

OTHER TIPS

Yes it's possible to run the jbpm process engine completely standalone, as a simple java program. No J2EE container needed. At least this is the case with jbpm 4.4

As far as the code requirement goes,

  1. setup your jbpm database schema
  2. add the following jars from the jbpm distribution library to the applications classpath: antlr-runtime.jar antlr.jar dom4j.jar hibernate-core.jar javassist.jar jbpm.jar slf4j-api.jar slf4j-jdk14.jar slf4j-log4j12.jar commons-collections.jar jta.jar juel-api.jar juel-engine.jar juel-impl.jar mail.jar AND the necessary JDBC drivers for the DB that you are using.
  3. and your standalone class looks like this:

    package test.ayusman;

    import java.util.HashMap;
    import java.util.Map;

    import org.jbpm.api.Configuration;
    import org.jbpm.api.ExecutionService;
    import org.jbpm.api.ProcessEngine;
    import org.jbpm.api.ProcessInstance;
    import org.jbpm.api.RepositoryService;

    public class ProcessDeployer {

        // Create a process engine that can be used for all other work...
        // ProcessEngine is starting point for all other application.
        private static ProcessEngine jbpmProcessEngine = new Configuration()
                .setResource("jbpm.cfg.xml").buildProcessEngine();
        // private static Logger logger = Logger.getLogger(JBPMDao.class);

        private static RepositoryService repositoryService = null;
        private static ExecutionService executionService = null;
        private static ProcessInstance pi = null;
        private static String processInstanceState;
        private static String processInstanceId;


        public static void main(String[] args) {
            try {

                ProcessDeployer ejm = new ProcessDeployer();

                //Start the process...
                ejm.startProcess();

                //Analyze process... just a small fancy method
                ejm.analyzeProcess();


            } catch (Exception e) {
                e.printStackTrace();
            }

        }// End of main()


        void startProcess() throws Exception
        {

            repositoryService = jbpmProcessEngine.getRepositoryService();
            executionService =  jbpmProcessEngine.getExecutionService();

            //NOTE: The example assumes that the process definition file name is: your_process.jpdl.xml
            processInstanceId = repositoryService.createDeployment().addResourceFromClasspath("your_process.jpdl.xml").deploy();             

            //NOTE: The jpdl file has key name as "Java"
            pi = executionService.startProcessInstanceByKey("Java");  

            System.out.println("Obtained processInstanceId is: "+processInstanceId);             
        }

        void analyzeProcess() throws Exception
        {
            processInstanceState = pi.getState();
            System.out.println("processInstanceState is: "+processInstanceState);
            System.out.println("processInstanceId is: "+processInstanceId);
        }


    }// End of class ProcessDeployer
  1. Note that when you are running the process engine from with in the SWT application, the process engine resides on the same JVM as the SWT, so make sure that you allocate enough space.

Hope this helps :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top