Search code examples
droolsdrools-guvnor

Extract a Drools Guvnor .pkg file


I am new to Drools and to Guvnor. We have created DRL file and loaded in Guvnor and we got the package built. It has resulted in a .pkg file. We download this .pkg file from Guvnor and use it for our different projects. Now I am trying to see things inside the .pkg file, but I am not sure how to open this.


Solution

  • The following code examines a knowledge base and will write out the names of all the packages that were loaded into it and the names of the rules in those packages. There's probably a bit more info that can be extracted, but I have never found the need. The only thing you won't get is the source code of the rules. But going by your explanation, that is available in Guvnor.

    /**
     * Return a string containing the packages used to build the knowledge base.
     */
    public static String knowledgeBaseDetails(KieBase kbase) {
        if (kbase == null) {
            return "Knowledge Base is null.";
        } else {
            StringBuilder sb = new StringBuilder(
                    "Knowledge base built from the following packages:");
            Collection<KiePackage> packages = kbase
                    .getKiePackages();
            for (KiePackage kp : packages) {
                sb.append("\n    Package: [" + kp.getName() + "]");
                for (Rule rule : kp.getRules()) {
                    sb.append("\n        Rule: [" + rule.getName() + "]");
                }
            }
            return sb.toString();
        }
    }
    

    It's almost the same for Drools 5 and 6. Generally for the earlier versions of Drools, just change Kie to Knowledge.