1

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?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Rama Vadakattu
  • 1,266
  • 2
  • 16
  • 24

1 Answers1

1

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

  1. Go to you play installation directory the go inside folder >> framework >> pym >> play
  2. Open application.py
  3. Go the method def getClasspath(self):
  4. 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')))

  5. Now drools will be able to find the play models.Everything looks fine.

Solution 2 is

YOu can invoke play server like below

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Dplay.debug=yes -Dplay.id= -Dapplication.path=/home/przemek/pn -Djava.endorsed.dirs=/opt/play/framework/endorsed -javaagent:/opt/play/framework/play-1.2.4.jar -Dfile.encoding=UTF-8 -classpath "Play computed classpath" and path to tmp classes  Play.server.Server

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.

Rama Vadakattu
  • 1,266
  • 2
  • 16
  • 24