如何在桌面应用程序中设置jBPM?

前端之家收集整理的这篇文章主要介绍了如何在桌面应用程序中设置jBPM?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想要的是:

我正在创建一个原型,它应该读取bpmn2文件并列出其所有任务.

我在用什么:

目前我有一个使用jBPM 6的简单Maven应用程序.我不需要任何应用程序服务器,工作台等,因为它只是一个简单的桌面应用程序.

问题:

如果我像这样初始化引擎(as suggested by the official documentation):

RuntimeEnvironment environment = 
                RuntimeEnvironmentBuilder.Factory.get()
                .newDefaultInMemoryBuilder()
                .persistence(false)
                .addAsset(ResourceFactory.newClassPathResource("poc4.bpmn2"),ResourceType.BPMN2)
                .get();

我收到此错误

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.persistence.jpa
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at org.jbpm.runtime.manager.impl.DefaultRuntimeEnvironment.init(DefaultRuntimeEnvironment.java:72)
    at org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder.get(RuntimeEnvironmentBuilder.java:314)
    at org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder.get(RuntimeEnvironmentBuilder.java:56)
    at com.test.jbpmpoc.main(App.java:11)

请注意,我正在尝试使用明确禁用的持久性启动引擎,但我认为不需要,因为文档说明了the engine does NOT use persistence by default.

我知道的:

根据我的研究,至少有两种初始化引擎的方法.

>使用提供运行时环境的构建器 – 我已经在做了.这似乎是the most recommended way of doing it,因为默认情况下会初始化所有服务.但是,如herehere所述,如果你想使用Tasks(这是我做的事情),这种方法需要设置持久性.
>手动初始化所​​有内容.我不太喜欢这个,因为运行一个简单的应用程序听起来太费劲了.
>使用其他运行时环境构建器.

我尝试过的:

起初,我尝试使用persistence.xml suggested by the documentation,但在创建EntityManagerFactory时出现了不同的错误

Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at com.test.jbpmpoc.App.main(App.java:30)
Caused by: org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [jdbc/jbpm-ds]
    at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:141)
    at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:112)
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
    ... 3 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property,or as an applet parameter,or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:135)
    ... 20 more

我没有使用应用程序服务器,也没有JTA数据源和ORM文件,因此我注释了指向这些文件的行以修复此JNDI错误,然后我得到了另一个异常:

Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.NamedQuery.lockMode()Ljavax/persistence/LockModeType;
    at org.hibernate.cfg.annotations.QueryHintDefinition.determineLockOptions(QueryHintDefinition.java:138)
    at org.hibernate.cfg.annotations.QueryBinder.bindQuery(QueryBinder.java:72)
    at org.hibernate.cfg.annotations.QueryBinder.bindQueries(QueryBinder.java:219)
    at org.hibernate.cfg.AnnotationBinder.bindQueries(AnnotationBinder.java:374)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:618)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at com.test.jbpmpoc.App.main(App.java:30)

我很确定我离这里越来越近了.如果我在应用程序服务器外运行,是否真的需要JTA数据源和ORM文件? jBPM安装程序没有附带这些,我在哪里可以找到它们?

我还尝试使用空构建器而不是默认构建器之一,因此我需要手动初始化所​​有内容,包括TaskService,如果我想管理任务(列表,执行等),我认为我需要启动它. .但是,它也需要persistence.xml,因为我一直收到No Persistence provider消息.

编辑

我之前应该猜到NoSuchMethodError异常是由错误版本的Maven工件引起的.我还在我的持久性定义中使用JTA作为我的事务策略,但是没有提供任何jta数据源.但是,现在我已经更改了我的pom.xml和persistence.xml,我收到此错误

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.test.jbpmpoc.App.main(App.java:30)
Caused by: org.hibernate.HibernateException: Errors in named queries: GetProcessInstanceIdByCorrelation
    at org.hibernate.impl.SessionFactoryImpl.

似乎JBPMorm.xml文件中的一个命名查询错误的.我从JBPM source code复制了这个文件.

有关我的Java项目的更多信息:

> My JBPMorm.xml
> My persistence.xml
> My pom.xml
> My project structure

我发现的所有示例和教程都专注于创建在应用程序服务器上运行的Web应用程序,但在我的情况下,缺少应用程序服务器需要一个我仍未找到的解决方法.有没有人设法使用jBPM 6运行简单的桌面应用程序?

最佳答案
我可能没有直接回答你的问题,但是我觉得可以引导你找到解决方案.

我从问题的推论是,基本上我们想要以编程方式(没有像数据库这样的外部依赖关系)创建jBPM运行时并对其进行操作.

我建议你阅读用户指南 – 第6.8节.测试,它可以帮助您测试您的过程,您测试过程在特定用例中是否按预期运行,

http://docs.jboss.org/jbpm/v6.2/userguide/jBPMBPMN2.html#d0e4026

文档建议您扩展JbpmJUnitBaseTestCase并创建junit测试用例. JbpmJUnitBaseTestCase类将逻辑抽象为createRuntimeManager,assertProcessInstanceCompleted等…您可以引用或重用此类来构建应用程序.

https://github.com/droolsjbpm/jbpm/blob/master/jbpm-test/src/main/java/org/jbpm/test/JbpmJUnitBaseTestCase.java

原文链接:https://www.f2er.com/java/437165.html

猜你在找的Java相关文章