只能导入一个类型。 models.XYZ 解析为一个包
过去 1 天我一直在尝试解决该问题,但无法解决。
我正在从游戏模型中触发流口水(规则)。它在我当地的环境中运行得非常好。
但是,当我在Solaris盒子上的生产中部署相同的应用程序时,我收到以下错误
Error = Unable to resolve ObjectType 'Tracker' : [Rule name='PM APPROVAL']
Unable to resolve ObjectType 'User' : [Rule name='SEND MAILS']
Unable to resolve ObjectType 'Tracker' : [Rule name='SEND MAILS']
Error importing : 'models.Tracker'Error importing : 'notifications.TrackerMails'Error importing : 'models.User'Rule Compilation error : [Rule name='SEND MAILS']
drools/Rule_SEND_MAILS_0.java (2:23) : Only a type can be imported. notifications.TrackerMails resolves to a package
drools/Rule_SEND_MAILS_0.java (2:57) : Only a type can be imported. models.Tracker resolves to a package
drools/Rule_SEND_MAILS_0.java (2:95) : Only a type can be imported. models.User resolves to a package
drools/Rule_SEND_MAILS_0.java (8:422) : TrackerMails cannot be resolved
drools/Rule_SEND_MAILS_0.java (8:455) : $user cannot be resolved to a variable
drools/Rule_SEND_MAILS_0.java (8:461) : $tracker cannot be resolved to a variable
获取drooolssession的示例代码。我通过在一些论坛中查看添加了变量classLoader,但我仍然没有解决问题。
StatefulKnowledgeSession dsession = null;
ClassLoader classLoader = TrackerUtil.class.getClassLoader();
KnowledgeBuilderConfiguration kBuilderConfiguration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, classLoader);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
KnowledgeBaseConfiguration kbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, classLoader);
'''''
builder.add(ResourceFactory.newFileResource(new File(uri)),ResourceType.DRL);
''''
builder.add(ResourceFactory.newFileResource(new File(uri)),ResourceType.DRF);
.......
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
dsession = knowledgeBase.newStatefulKnowledgeSession();
return dsession;
任何人都可以帮助我如何解决这个问题吗?
I have been trying to resolve the problem for the past 1 day but i could not able to resolve.
Iam triggering drools (rules) from the play models.It is working perfectly fine in my local environment.
But when iam deploying the same application on production on a solaris box iam getting the following error
Error = Unable to resolve ObjectType 'Tracker' : [Rule name='PM APPROVAL']
Unable to resolve ObjectType 'User' : [Rule name='SEND MAILS']
Unable to resolve ObjectType 'Tracker' : [Rule name='SEND MAILS']
Error importing : 'models.Tracker'Error importing : 'notifications.TrackerMails'Error importing : 'models.User'Rule Compilation error : [Rule name='SEND MAILS']
drools/Rule_SEND_MAILS_0.java (2:23) : Only a type can be imported. notifications.TrackerMails resolves to a package
drools/Rule_SEND_MAILS_0.java (2:57) : Only a type can be imported. models.Tracker resolves to a package
drools/Rule_SEND_MAILS_0.java (2:95) : Only a type can be imported. models.User resolves to a package
drools/Rule_SEND_MAILS_0.java (8:422) : TrackerMails cannot be resolved
drools/Rule_SEND_MAILS_0.java (8:455) : $user cannot be resolved to a variable
drools/Rule_SEND_MAILS_0.java (8:461) : $tracker cannot be resolved to a variable
The sample code which gets the drooolssession.I have add variable classLoader by looking in some forums but still i have not fixed the issue.
StatefulKnowledgeSession dsession = null;
ClassLoader classLoader = TrackerUtil.class.getClassLoader();
KnowledgeBuilderConfiguration kBuilderConfiguration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, classLoader);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
KnowledgeBaseConfiguration kbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, classLoader);
'''''
builder.add(ResourceFactory.newFileResource(new File(uri)),ResourceType.DRL);
''''
builder.add(ResourceFactory.newFileResource(new File(uri)),ResourceType.DRF);
.......
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
dsession = knowledgeBase.newStatefulKnowledgeSession();
return dsession;
Can anyone please help on how can i resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过两天的努力终于解决了这个问题!!
问题来了,因为 Drools 无法解析 play 模型。在 eclipse 中,它工作正常,因为它将 eclipse/classes 添加到类路径。但是每当您运行“Play run”时,drools 就无法找到 play.models。所以为了克服这个问题,我们需要将“tmp/classes”添加到类路径中。
下面就是我们如何将
在方法中找到行 classpath.append(os.path.normpath(os.path.join(self.path, 'conf')) ) 在该行下方添加以下行
classpath.append(os.path.normpath(os.path.join(os.path.join(self.path, 'tmp'),'classes')))
现在流口水了能够找到游戏模型。一切看起来都很好。
解决方案 2
您可以像下面这样调用播放服务器
即使上面的工作正常。您可以通过运行命令 play classpath 来获取播放计算的类路径。对于类路径,Linux 中的分隔符是“:”,而在 Windows 中这是 ”;”
上述解决方案有效,但我真的不明白为什么部分?
游戏如何能够解析模型,而流口水则无法解析相同的模型?
如果您知道上述答案,请告诉我。
Finally i resolved the problem after two day effort !!
The problem comes as the Drools is not able to resolve the play models.In eclipse it works fine as it add eclipse/classes to the classpath.But whenever you run "Play run" drools is not able to find the play.models.So to overcome this we need to add the "tmp/classes" to the classpath.
Here is how we can add
In method find the line classpath.append(os.path.normpath(os.path.join(self.path, 'conf'))) below the line add the following line
classpath.append(os.path.normpath(os.path.join(os.path.join(self.path, 'tmp'),'classes')))
Now drools will be able to find the play models.Everything looks fine.
Solution 2 is
YOu can invoke play server like below
Even the above works fine.You can get the play computed classpath by running the command play classpath.For classpath the delimiter in linux is ":" whereas in windows it is ";"
The above solutions works But i really didn't understand the why part ?
How play is able to resolve the models where as drools is not able to resolve the same the models?
Please let me know if you know the answer to above.