Version 2

    I'm afraid that is is actually not that the drool can't read/found the drl file, but it is because some .jar that needed by drools is not accessible. It is because when I purposely make a wrong syntax in drl file, drools still be able to detect it.

     

    The workaround is quite easy if the case is the same like mine. Just repeating what I said before, with a little more details.

     

    Server : JBoss AS 4.0.4GA with EJB3 RC8

    IDE : JDeveloper

     

    Say the server configuration that being used is "all" (there are also "minimal" and "default"), then go the directory

     

    /lib.

     

    That is, base on this case, if you're using other server like tomcat, maybe you should copy it into tomcat's lib folder. However this is just what I'm thinking though, not tried it yet.

     

    Instead of using getResourceAsStream() to get a drl's content, I just use a normal FileReader, and use an absolute path to access it (the drl file is in C: and Jboss is in D:). It brings a little convenience as we dont need to recompile the whole project if any changes being made in drl file. Also it is because my rule will soon be added into database so it don't really matter for now.

     

    Anyway my code is as follow :

    
            WorkingMemory workingMemory;
    
            log.info("=====================Start rule ");       
           
            final PackageBuilder builder = new PackageBuilder();      
            
            if (ruleBase != null) {
                log.info("rulebase not null : ");
                workingMemory = ruleBase.newWorkingMemory();
            } else {
                ruleBase = RuleReader. getRule(fileName);
                workingMemory = ruleBase.newWorkingMemory();
            }
    
           
            try {
                workingMemory.assertObject(object);          
            } catch (Exception ex) {
                log.info("An error asserting object!!");
                ex.printStackTrace();
            }
    
            workingMemory.fireAllRules();
    
    

     

    RuleReader's getRule(String fileName) code :

     

              
            PackageBuilder builder = new PackageBuilder();
            log.info("READY TO READ : ");
    
            boolean exists = (new File(fileName)).exists();
            if (exists) {
                log.info("FILE EXISTS");
            } else {
                log.info("FILE NOT EXISTS");
            }  
    
            Reader source = new FileReader(fileName);      
    
        
            try {
                builder.addPackageFromDrl(source);
            } catch (IOException ioe) {
                log.info("IOException");
            } catch (DroolsParserException dpe) {
                log.info("DroolsParserException");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
          
            Package pkg = builder.getPackage();      
            ruleBase = RuleBaseFactory.newRuleBase();     
            ruleBase.addPackage(pkg);
    
            return ruleBase;