<div dir="ltr"><br><div>   There are several different ways of doing it, but here is a snippet to help creating an in-memory kjar with default kbases and ksessions:</div><div><br></div><div><br></div><div><div>    public static byte[] createKJar(KieServices ks,</div>
<div>                                    ReleaseId releaseId,</div><div>                                    String pom,</div><div>                                    String... drls) {</div><div>        KieFileSystem kfs = ks.newKieFileSystem();</div>
<div>        if( pom != null ) {</div><div>            kfs.write(&quot;pom.xml&quot;, pom);</div><div>        } else {</div><div>            kfs.generateAndWritePomXML(releaseId);</div><div>        }</div><div>        KieResources kr = KieServices.getResources();</div>
<div>        for (int i = 0; i &lt; drls.length; i++) {</div><div>            if (drls[i] != null) {</div><div>                kfs.write( kr.newByteArrayResource( drls[i].getBytes() ).setSourcePath(&quot;my/pkg/drl&quot;+i+&quot;.drl&quot;) );</div>
<div>            }</div><div>        }</div><div>        KieBuilder kb = ks.newKieBuilder(kfs).buildAll();</div><div>        if( kb.getResults().hasMessages( org.kie.api.builder.Message.Level.ERROR ) ) {</div><div>            for( org.kie.api.builder.Message result : kb.getResults().getMessages() ) {</div>
<div>                System.out.println(result.getText());</div><div>            }</div><div>            return null;</div><div>        }</div><div>        InternalKieModule kieModule = (InternalKieModule) ks.getRepository()</div>
<div>                .getKieModule(releaseId);</div><div>        byte[] jar = kieModule.getBytes();</div><div>        return jar;</div><div>    }</div><div><br></div></div><div>   Please note that you usually don&#39;t need the byte[] back, so you can ignore everything after the last 3 lines of the code. Also, the error check in the snippet is just printing to sysout. You should handle this accordingly in your application.</div>
<div><br></div><div>   Hope it helps.</div><div><br></div><div>   Edson</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 3, 2013 at 3:25 AM, pmander <span dir="ltr">&lt;<a href="mailto:paul.s.mander@gmail.com" target="_blank">paul.s.mander@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I head previously read that but didn&#39;t spot the bit that mentions creating<br>
from a drl defined as a String. I take it this can be done from<br>
KieFileSystem.<br>
<br>
String rules = ...<br>
KieFileSystem kfs = kieServices.newKieFileSystem();<br>
kfs.write(kieServices.getResources().newReaderResource(new<br>
StringReader(rules)));<br>
<br>
This throws an exception complaining that the resource doesn&#39;t have a source<br>
or target path set.<br>
<br>
Is there a way to push a dynamically created drl into this without writing<br>
it to disk first?<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044p4027059.html" target="_blank">http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044p4027059.html</a><br>

<div class="HOEnZb"><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">  Edson Tirelli<br>  Principal Software Engineer <div>  Red Hat Business Systems and Intelligence Group<br><br></div></div>
</div>