严重:上下文初始化失败 java.lang.NoClassDefFoundError:org / activiti / bpmn / model / FlowElement
服务类
package com.activiti.deploy.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.EndEvent;
import org.activiti.bpmn.model.FormProperty;
import org.activiti.bpmn.model.ParallelGateway;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.ScriptTask;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.bpmn.model.UserTask;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.activiti.deploy.model.ActivitiForm;
@Service("ActivtiInterfaceService")
@Transactional
public class ActivitiInterfaceServiceImpl implements ActivtiInterfaceService{
public boolean deployinActiviti(ActivitiForm activitiForm) throws IOException{
boolean deployed = false;
BpmnModel model = new BpmnModel();
Process process = new Process();
model.addProcess(process);
process.setId("my-process");
process.setName("Qmplus test");
process.addFlowElement(createStartEvent());
process.addFlowElement(createUserTask("task1","First task","kermit",activitiForm));
process.addFlowElement(createUserTask("task2","Second task","kermit",activitiForm));
List<SequenceFlow> outgoing = new ArrayList<SequenceFlow>();
outgoing.add(createSequenceFlow("task3","task4"));
outgoing.add(createSequenceFlow("task3","task2"));
process.addFlowElement(createParallelTask("task3","option task",outgoing));
process.addFlowElement(createEndEvent());
process.addFlowElement(createScriptTask("task4","script task","12343"));
process.addFlowElement(createSequenceFlow("start","task1"));
process.addFlowElement(createSequenceFlow("task1","task3"));
process.addFlowElement(createSequenceFlow("task3","task2"));
process.addFlowElement(createSequenceFlow("task3","task4"));
process.addFlowElement(createSequenceFlow("task2","end"));
process.addFlowElement(createSequenceFlow("task4","end"));
// 2. Generate graphical information
new BpmnAutoLayout(model).execute();
/*DefaultHttpClient dhc = new DefaultHttpClient();
dhc.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials("kermit", "kermit"));
HttpPost hp = new HttpPost("http://localhost:8080/activiti-rest/service/deployment");
hp.addHeader( "Content-Type", "multipart/form-data; boundary=---------------------------28617237579832" );
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("localhost", 8080, "http"), basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
MultipartEntity se = new MultipartEntity();
byte[] xml = new BpmnXMLConverter().convertToXML(model);
FileOutputStream fileOuputStream =
new FileOutputStream("target/test.bpmn20.xml");
fileOuputStream.write(xml);
fileOuputStream.close();
File file = new File("target/test.bpmn20.xml");
se.addPart("success", new StringBody("success", Charset.forName("UTF-8")));
se.addPart("failure", new StringBody("failure", Charset.forName("UTF-8")));
FileBody fileBody = new FileBody(file);
se.addPart("deployment", fileBody);
hp.setEntity(se);
// HttpResponse processResponse = dhc.execute(hp,localcontext);
//String data=IOUtils.toString(processResponse.getEntity().getContent());
//System.out.println("reader"+data);
// dhc.getConnectionManager().shutdown(); */
return deployed;
}
protected UserTask createUserTask(String id, String name, String assignee, ActivitiForm activitiForm)
{
UserTask userTask = new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(assignee);
List<FormProperty> formProperties = new ArrayList<FormProperty>();
formProperties.add(createFormProperty(activitiForm));
userTask.setFormProperties(formProperties);
return userTask;
}
protected FormProperty createFormProperty(ActivitiForm activitiForm){
FormProperty formproperty = new FormProperty();
formproperty.setName(activitiForm.getTitle());
formproperty.setType(activitiForm.getType());
return formproperty;
}
protected SequenceFlow createSequenceFlow(String from, String to)
{
SequenceFlow flow = new SequenceFlow();
flow.setSourceRef(from);
flow.setTargetRef(to);
return flow;
}
protected ParallelGateway createParallelTask(String id, String name, List<SequenceFlow> outgoingFlows)
{
ParallelGateway p = new ParallelGateway();
p.setId(id);
p.setName(name);
p.setOutgoingFlows(outgoingFlows);
return p;
}
protected ScriptTask createScriptTask(String id, String name, String script)
{
ScriptTask st = new ScriptTask();
st.setId(id);
st.setScript("out.println(" + script + ")");
st.setScriptFormat("groovy");
st.setName(name);
return st;
}
protected StartEvent createStartEvent()
{
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
return startEvent;
}
protected EndEvent createEndEvent()
{
EndEvent endEvent = new EndEvent();
endEvent.setId("end");
return endEvent;
}
}
和pom.xml如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringActiviti</groupId>
<artifactId>ActivitiLearning</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ActivitiLearning Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<springFramework.version>4.2.0.RELEASE</springFramework.version>
<jackson.version>2.5.3</jackson.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springFramework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springFramework.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-layout</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>5.17.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>ActivitiLearning</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>ActivitiLearning</finalName>
</build>
<repositories>
<repository>
<id>Alfresco Maven Repository</id>
<url>https://maven.alfresco.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>