cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Process Instance with Java

zlatan316
Champ on-the-rise
Champ on-the-rise
Hi all,

I have a linux server setup with activiti that we use to create bpmn process via Activiti Explorer.
I am trying to write a class that will create an activiti process through code, and is runnable as a JAR on the server. Here is what i have so far:

   public static void spawnBPMNProcess() {
      System.out.println("Started spawnBPMNProcess()");
      Authentication.setAuthenticatedUserId("admin");
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
            .buildProcessEngine();
      RepositoryService repositoryService = processEngine.getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();
      IdentityService identityService = processEngine.getIdentityService();
      System.out.println("Referencing BPMN diagram to launch…");
      repositoryService.createDeployment()
            .addClasspathResource("liveprocess.bpmn20.xml")
            .deploy();
      Map<String, Object> variableMap = new HashMap<String, Object>();
      variableMap.put("clientString", "test_ACP");
      
      identityService.setAuthenticatedUserId("admin");
      
      System.out.println("Launching process…");
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableMap", variableMap);
      System.out.println("Process Definition ID: " + processInstance.getProcessDefinitionId());
      System.out.println("Activiti ID: " + processInstance.getActivityId());
      System.out.println("Launch complete!");
   }


This code however gives me the below errors:
——————–
java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver
——————–
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/activiti
——————–

This seems to indicate I need to reference the database that exists on the server, how can i resolve this issue?

With Thanks.
4 REPLIES 4

balsarori
Champ on-the-rise
Champ on-the-rise
Hi,

Seems that your code is missing JDBC driver jar for H2 database.

Do you plan to run the code inside the Activiti Explorer webapp or as a separate Java application?

Hi, I plan to initially create the process from a Java app, then manage it in the Activiti Explorer UI. Which JAR would I need to include along with my other 3rd party jars?

jbarrez
Star Contributor
Star Contributor
As Bassam says, from your exception it seems the H2 driver is missing, dependency is here: http://mvnrepository.com/artifact/com.h2database/h2

zlatan316
Champ on-the-rise
Champ on-the-rise
Thanks, this was a dependancy missing from my classpath. I actually wanted to use mysql anyway so I added the steps specified inthe Activiti  in action book and it worked fine.