Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:48:40+00:00 2026-05-23T00:48:40+00:00

Recently i was working on a drools project where i came across certain issues

  • 0

Recently i was working on a drools project where i came across certain issues and i need some help.
In my project i access jar at runtime by making use of the URLClassLoader.Here is the code :

Object object=null;
 Class myclass=null;
 URL jarPath=null;
 try{
    jarPath=new File("lib/Billing.jar").toURI().toURL();
    URLClassLoader loader = new URLClassLoader(new URL[] { jarPath },ClassLoader.getSystemClassLoader());
    ruleclass = loader.loadClass("dynamicclasses.Billing");
    object = ruleclass.newInstance();                       
}
catch (Exception e) {e.printStackTrace}

After getting the class instance I will set the values and pass the object to my drools class

new DroolsClass().fireRules(object);

The drools class contain the following code :

public class DroolsClass {
public void fireRules(Object object){   
        try {
            KnowledgeBase kbase = readKnowledgeBase();
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
            ksession.insert(object);
            ksession.fireAllRules();                    
            logger.close();

        } catch (Throwable t) {
            t.printStackTrace();    
        }

}
private static KnowledgeBase readKnowledgeBase() throws Exception {

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(ResourceFactory.newFileResource("./rulefiles/testing.drl"), ResourceType.DRL);
            KnowledgeBuilderErrors errors = kbuilder.getErrors();
        // ------ some code
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        return kbase;
}

Next I have a drl file testing.drl which is present in the file directoty and which accesses the same class dynamicclasses.Billing which is present in Billing.jar

Here is the drl file content :

import dynamicclasses.Billing;

rule "rule 3"

salience 10 
dialect "mvel" 
no-loop true
when
     m : Billing(bplan=="plan1")
then
    System.out.println("You have opted for plan1");   
end

The problem I encounter is when the jar i.e Billing.jar get updated at runtime the drl file i.e testing.drl
is not able to access the updated jar.

The following things i am trying to do.

1) I will create jar at runtime and update it if required.
2) I will create a drl file at runtime which will import the class present in the jar i.e. dynamicclasses.Billing

I am able to access the updated jar contents in my java class using URLClassLoader .But once i pass the object to my drools class I get the following exception

Unable to resolve ObjectType 'Billing' : [Rule name='rule 3']

Error importing : 'dynamicclasses.Billing'
java.lang.IllegalArgumentException: Could not parse knowledge.

If i restart my application i get no exception since the jar is already present but the object doesn’t seem to pass to the drl and i get no result.

I made the following changes to the code :

URLClassLoader loader = new URLClassLoader(new URL[] { jarPath },this.getClass().getClassLoader());

Here i get the same exception initially. But after i restart my application it works fine and the rule get fired and i will get the result.

But again if i update the jar it will access only the previous content.

So its clear that the drl file is not able to access the jar intially or even after updating.
Is there any way so that i can make it work?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:48:41+00:00Added an answer on May 23, 2026 at 12:48 am

    Thanks 🙂 Finally I am able to solve this.You need to pass your custom class loader not only to KnowledgeBuilderConfiguration but also to your KnowledgeBaseConfiguration to make even your knowledge base aware of your custom class loader .

    private static KnowledgeBase readKnowledgeBase(ClassLoader loader) throws Exception {
    
            KnowledgeBuilderConfiguration kBuilderConfiguration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, loader);
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
    
            KnowledgeBaseConfiguration kbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, loader);
    
            kbuilder.add(ResourceFactory.newFileResource("./rulefiles/testing.drl"), ResourceType.DRL);
            KnowledgeBuilderErrors errors = kbuilder.getErrors();
    
            if (errors.size() > 0) {
                for (KnowledgeBuilderError error: errors) {
                    System.err.println(error);
                }
                throw new IllegalArgumentException("Could not parse knowledge.");
            }
    
            KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
            return kbase;
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am recently working in a project. There I need to convert language from
I'm recently working on a semantic web application project using Rowlex. I've reached some
I've recently been working with a simple Twitter API for PHP and came across
I'm recently working on a project in which I need to port a portion
Having recently begun working on a project which might need (good) scaling possibilities, I've
I am recently working on a .net 2.0 project I have to read some
I recently was working on a little python project and came to a situation
I recently was working with a subversion project that checked out code not only
I recently began working on a large project that contains a huge number of
Recently, I has been working with Drools component. I found a very interesting thing.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.