2012-12-28 57 views
1

我使用以下代碼訪問的Drools的Guvnor:訪問的Drools的Guvnor從OSGi包

KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration(); 
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent", kaconf); 
kagent.applyChangeSet(ResourceFactory.newClassPathResource("drools/change-set.xml")); 
StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession(); 

不幸的是KnowledgeAgentFactory類似乎並沒有被OSGI準備,因爲它使用Class.forName()加載劑供應商。 KnowledgeAgentFactory駐留在知識api包中,並在drools-core bundle中提供實現。顯然knowledge-api在OSGI容器中沒有看到drools-core。因此我得到以下異常:

Caused by: java.lang.RuntimeException: Provider org.drools.agent.impl.KnowledgeAgentProviderImpl could not be set. 
    at org.drools.agent.KnowledgeAgentFactory.loadProvider(KnowledgeAgentFactory.java:191)[162:org.drools.api:5.5.0.Final] 
    at org.drools.agent.KnowledgeAgentFactory.getKnowledgeAgentProvider(KnowledgeAgentFactory.java:178)[162:org.drools.api:5.5.0.Final] 
    at org.drools.agent.KnowledgeAgentFactory.newKnowledgeAgentConfiguration(KnowledgeAgentFactory.java:129)[162:org.drools.api:5.5.0.Final] 

是否有解決此問題的方法?

回答

0

你可能需要一個require-bundle清單條目來幫助你自己,因爲它似乎不能正確地處理那些導入,我會說在那個時候它可能是最好的方式來讓它工作。

Require-Bundle如在OSGi維基

+0

定義都需要束和Import-捆綁似乎在這裏幫助 – hoaz