6 Replies Latest reply on Dec 5, 2009 1:58 PM by saraswati.santanu

    [jbpm 4.2] My first simple application doesn't work :(

    -silver-

      I'm trying to develop my first workflow with jbpm 4.2 and netbeans but it doesn't works.
      I created a new project called "displayproject" and imported as libraries the file jbpm.jar that is in the root jbpm's folder and all the files that are in the "lib" folder.
      The project contains only those two files:
      Display.java

      package displayproject;
      
      import java.util.List;
      import java.util.Map;
      import java.util.Set;
      import org.jbpm.api.Execution;
      import org.jbpm.pvm.internal.model.Activity;
      import org.jbpm.pvm.internal.model.ObservableElement;
      import org.jbpm.pvm.internal.model.OpenProcessDefinition;
      import org.jbpm.pvm.internal.model.Transition;
      
      public class Display implements Activity{
       String message;
      
       public Display(String message){
       this.message=message;
       }
      
       public void execute(Execution execution){
       System.out.println(message);
       }
      }
      


      Main.java
      package displayproject;
      
      import org.jbpm.api.Execution;
      import org.jbpm.api.ProcessDefinition;
      
      public class Main{
      
       public static void main(String[] args) {
       ProcessDefinition processDefinition = ProcessFactory.build().node("a")
       .initial.behaviour(new Display("hello")).transition().to("b")
       .node("b").behaviour(new Display("world")).done();
       Execution execution = processDefinition.startExecution();
       }
      }
      


      in Main.java netbeans tell me that it's unable to find the object ProcessFactory and the method startExecution() .

      What'is wrong?
      What libraries have I to import in a process project? In what folder of jbpm4.2 could I find them?

      Thanks

        • 1. Re: [jbpm 4.2] My first simple application doesn't work :(
          sebastian.s

          You can't create process definitions programmatically this way anymore. Create a process definition and deploy it afterwards.

          You need to reference jbpm.jar and the main-folder and all the jars in the lib-subfolder.

          • 2. Re: [jbpm 4.2] My first simple application doesn't work :(
            sebastian.s

            "in the main-folder"

            • 3. Re: [jbpm 4.2] My first simple application doesn't work :(
              -silver-

              Sorry but I don't understood.
              Could you tell me how I've to change the code of my previous application for example?
              Thanks

              (I referenced all the needed libraries now)

              • 4. Re: [jbpm 4.2] My first simple application doesn't work :(
                saraswati.santanu

                Silver,
                the code you have written is wrong. It will not work that way. You need to create a Jpdl file first. You can use the Eclipse GPD for that. And then use the Jbpm API to create ProcessDefinition etc. There is no class called ProcessFactory in Jbpm4.

                Second point that you need to understand is that a ProcessDefinition can not be started, it is the ProecessInstance which should be started.

                Now assuming you have created a flow jpdl xml file, then your main class should look like this:

                private static ProcessEngine processEngine;
                
                private static RepositoryService repositoryService;
                private static ExecutionService executionService;
                
                static {
                 processEngine = Configuration.getProcessEngine();
                
                 repositoryService = processEngine.get(RepositoryService.class);
                 executionService = processEngine.getExecutionService();
                }
                
                /**
                 * @param args
                 */
                public static void main(String[] args) {
                 //create new deployment object and ask it to deploy your flow
                 String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("sampleprocess.jpdl.xml").deploy();
                
                 //now we query the process definition
                 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).uniqueResult();
                
                 //start the process instance with the Id of the process definition
                 ProcessInstance processInstance = executionService.startProcessInstanceById(processDefinition.getId());
                }
                


                • 5. Re: [jbpm 4.2] My first simple application doesn't work :(
                  -silver-

                  Thanks!
                  I tried with your code but I received this exception:

                  java.lang.ExceptionInInitializerError
                  Caused by: org.jbpm.api.JbpmException:
                   error: couldn't parse xml document : org.jbpm.api.JbpmException: resource jbpm.cfg.xml does not exist
                   error: parsing exception: null : java.lang.NullPointerException
                   at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:175)
                   at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:141)
                   at org.jbpm.pvm.internal.xml.Parse.checkErrors(Parse.java:190)
                   at org.jbpm.pvm.internal.cfg.ProcessEngineImpl.parse(ProcessEngineImpl.java:222)
                   at org.jbpm.pvm.internal.cfg.ProcessEngineImpl.setResource(ProcessEngineImpl.java:194)
                   at org.jbpm.api.Configuration.setResource(Configuration.java:109)
                   at org.jbpm.api.Configuration.getProcessEngine(Configuration.java:161)
                   at prova.Main.<clinit>(Main.java:17)
                  Caused by: org.jbpm.api.JbpmException
                   at org.jbpm.pvm.internal.xml.ProblemList.getJbpmException(ProblemList.java:171)
                   ... 7 more
                  Caused by: java.lang.NullPointerException
                   at org.jbpm.pvm.internal.util.XmlUtil.attribute(XmlUtil.java:289)
                   at org.jbpm.pvm.internal.env.JbpmConfigurationParser.parseDocument(JbpmConfigurationParser.java:68)
                   at org.jbpm.pvm.internal.xml.Parser.execute(Parser.java:396)
                   at org.jbpm.pvm.internal.xml.Parse.execute(Parse.java:158)
                   ... 5 more
                  Exception in thread "main"


                  What could be the problem? Those are the two files of my project:
                  Main.java
                  import org.jbpm.api.Configuration;
                  import org.jbpm.api.ExecutionService;
                  import org.jbpm.api.ProcessDefinition;
                  import org.jbpm.api.ProcessEngine;
                  import org.jbpm.api.ProcessInstance;
                  import org.jbpm.api.RepositoryService;
                  
                  public class Main{
                   private static ProcessEngine processEngine;
                  
                   private static RepositoryService repositoryService;
                   private static ExecutionService executionService;
                  
                   static {
                   processEngine = Configuration.getProcessEngine();
                  
                   repositoryService = processEngine.get(RepositoryService.class);
                   executionService = processEngine.getExecutionService();
                   }
                  
                   /**
                   * @param args
                   */
                   public static void main(String[] args) {
                   //create new deployment object and ask it to deploy your flow
                   String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("sampleprocess.jpdl.xml").deploy();
                  
                   //now we query the process definition
                   ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).uniqueResult();
                  
                   //start the process instance with the Id of the process definition
                   ProcessInstance processInstance = executionService.startProcessInstanceById(processDefinition.getId());
                   }
                  }
                  


                  and sampleprocess.jpdl
                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <process name="sampleprocess" xmlns="http://jbpm.org/4.0/jpdl">
                   <start name="start1" g="238,73,48,48">
                   <transition name="to end1" to="end1" g="-45,-20"/>
                   </start>
                   <end name="end1" g="267,271,48,48"/>
                  </process>


                  Regarding to files that I described in my precedent post, I copied them directly from the PVM documentation, (Page 5 - 6 chapter 2). Could you send me the link to the correct PVM documentation?

                  Thanks!

                  • 6. Re: [jbpm 4.2] My first simple application doesn't work :(
                    saraswati.santanu

                    You are missing jbpm.cfg.xml file in your classpath. A very simple jbpm.cfg.xml may look like this:

                    <?xml version="1.0" encoding="UTF-8"?>
                    
                    <jbpm-configuration>
                    
                     <import resource="jbpm.default.cfg.xml" />
                     <import resource="jbpm.tx.hibernate.cfg.xml" />
                     <import resource="jbpm.jpdl.cfg.xml" />
                     <import resource="jbpm.identity.cfg.xml" />
                    
                     <!-- Job executor is excluded for running the example test cases. -->
                     <!-- To enable timers and messages in production use, this should be included. -->
                     <!--
                     <import resource="jbpm.jobexecutor.cfg.xml" />
                     -->
                    </jbpm-configuration>
                    


                    Create one such file in you classpath. That should make things progress further.

                    About the PVM documentation,the one they have there has examples using jbpm3.x. In 3.x there were those APIs. Jbpm4, I think, was not there when PVM docs were created. You should look at Jbpm dev-guide, user-guide and example with Jbpm4 instead.