<p>I don&#39;t see where it can fail. As long as we can make references to reosurces in the file system and resources in a jar, i think is enough. <br>
The idea of this new resource is to use it when you have the caching problem I described. If you don&#39;t have it, then you can use the old ClassPathResource (that by the way, converts the path to URL to get the last time the resource was modified :P)</p>

<p>Best Regards,<br>
 </p>
<div class="gmail_quote">El abr 17, 2011 8:50 a.m., &quot;Mauricio Salatino&quot; &lt;<a href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&gt; escribió:<br type="attribution">&gt; totally.., we know that.. but it&#39;s like there will be always a situation<br>
&gt; where that method will fail..<br>&gt; I think that we can made the assumption for now and then try to find those<br>&gt; missing bits.<br>&gt; <br>&gt; <br>&gt; On Sat, Apr 16, 2011 at 11:11 PM, Mark Proctor &lt;<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;wrote:<br>
&gt; <br>&gt;&gt;  On 17/04/2011 02:31, Esteban Aliverti wrote:<br>&gt;&gt;<br>&gt;&gt; Thanks pablo (aka baunax)!<br>&gt;&gt; I agree that resource -&gt; file: is not always possible. But what about<br>&gt;&gt; resource -&gt; URL? After all, i&#39;m converting resources to URLs.<br>
&gt;&gt;<br>&gt;&gt; The URL will have a pointer to the file inside of the jar.<br>&gt;&gt; <a href="http://www.exampledepot.com/egs/java.net/JarUrl.html">http://www.exampledepot.com/egs/java.net/JarUrl.html</a><br>&gt;&gt;<br>
&gt;&gt; Mark<br>&gt;&gt;<br>&gt;&gt;  Best regards,<br>&gt;&gt;  El abr 16, 2011 5:18 p.m., &quot;Pablo Nussembaum&quot; &lt;<a href="mailto:baunax@gmail.com">baunax@gmail.com</a>&gt;<br>&gt;&gt; escribió:<br>&gt;&gt; &gt; Sorry &quot;IF I *wasn&#39;t* clear&quot; :-P<br>
&gt;&gt; &gt;<br>&gt;&gt; &gt; On 04/16/2011 05:11 PM, Pablo Nussembaum wrote:<br>&gt;&gt; &gt;&gt; Sorry if I was clear. The problem when you do: ClassLoader.getResource(<br>&gt;&gt; &quot;resource.path&quot; ) is the the resource can be inside a war the in<br>
&gt;&gt; WEB-INF/classes and the war could be NOT exploded in<br>&gt;&gt; &gt;&gt; container that&#39;s is deployed, so the translation to something like<br>&gt;&gt; file:// is NOT reliable.<br>&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; On 04/16/2011 05:05 PM, Mauricio Salatino wrote:<br>
&gt;&gt; &gt;&gt;&gt; I&#39;m still thinking about that mapping and those assumptions<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; On Sat, Apr 16, 2011 at 5:05 PM, Mauricio Salatino &lt;<a href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&lt;mailto:<br>
&gt;&gt; <a href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&gt;&gt; wrote:<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; Can you? or Can&#39;t you?<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; On Sat, Apr 16, 2011 at 4:24 PM, Pablo Nussembaum &lt;<a href="mailto:baunax@gmail.com">baunax@gmail.com</a>&lt;mailto:<br>&gt;&gt; <a href="mailto:baunax@gmail.com">baunax@gmail.com</a>&gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; Esteban,<br>&gt;&gt; &gt;&gt;&gt; You can assume that a resource that was obtained from the classpath<br>&gt;&gt; exists in your filesystem, for instance it can be a file inside a jar or war<br>
&gt;&gt; that are not exploded. In other words you<br>&gt;&gt; &gt;&gt;&gt; can&#39;t always convert an URL to &quot;file://&quot;.<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; --<br>&gt;&gt; &gt;&gt;&gt; Bauna<br>&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; On 04/15/2011 08:52 AM, Esteban Aliverti wrote:<br>&gt;&gt; &gt;&gt;&gt;&gt; Hi Guys,<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; I want to discuss a problem I have found when using the combination of<br>
&gt;&gt; knowledge agent + classpathResources.<br>&gt;&gt; &gt;&gt;&gt;&gt; I will try to describe what am I doing first to give you some context.<br>&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; I&#39;m deploying drools-camel-server in a Tomcat 7 container. Inside the<br>
&gt;&gt; WEB-INF/classes directory I have some DRL files that I want to use.<br>&gt;&gt; &gt;&gt;&gt;&gt; My knowledge-services.xml file declares the following kagent:<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; &lt;drools:kagent id=&quot;kagent1&quot; kbase=&quot;kbase1&quot; new-instance=&quot;false&quot;&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt; &lt;drools:resources&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; &lt;drools:resource type=&quot;DRL&quot; source=&quot;*classpath*:simple.drl&quot;/&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; ...<br>&gt;&gt; &gt;&gt;&gt;&gt; &lt;/drools:resources&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt; &lt;/drools:kagent&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; When spring parses this configuration file it creates a KnowledgeAgent<br>&gt;&gt; instance with a ChangeSet containing all the listed resources.<br>
&gt;&gt; &gt;&gt;&gt;&gt; The next step is to start ResourceChangeNotifierService and<br>&gt;&gt; ResourceChangeScannerService.<br>&gt;&gt; &gt;&gt;&gt;&gt; So far so good.<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; The problem:<br>
&gt;&gt; &gt;&gt;&gt;&gt; The problem I&#39;m having is not directly related to drools, but I think<br>&gt;&gt; it is quite easy to provide a solution for the people that is in my same<br>&gt;&gt; situation.<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt; ClassPathResource is the class that represents a resource defined as<br>&gt;&gt; &quot;*classpath:&quot;*<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; This class has 2 important methods:<br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; public long getLastModified(){<br>&gt;&gt; &gt;&gt;&gt;&gt; return this.classLoader.getResource( this.path<br>&gt;&gt; ).openConnection().getLastModified();<br>&gt;&gt; &gt;&gt;&gt;&gt; }<br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; public InputStream getInputStream(){<br>&gt;&gt; &gt;&gt;&gt;&gt; return this.classLoader.getResourceAsStream( this.path );<br>&gt;&gt; &gt;&gt;&gt;&gt; }<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; The first method is used by ResourceChangeScannerService to check<br>&gt;&gt; whether the resource has changed or not. It works fine. When the resource in<br>&gt;&gt; the filesystem changes, the scanner detects<br>
&gt;&gt; &gt;&gt;&gt;&gt; the change without any problem.<br>&gt;&gt; &gt;&gt;&gt;&gt; The scanner ends up notifying the kagent about the change, and the<br>&gt;&gt; kagent passes the Resource to an instance of KnowledgeBuilder.<br>
&gt;&gt; &gt;&gt;&gt;&gt; An here is when things fail.<br>&gt;&gt; &gt;&gt;&gt;&gt; The kbuilder uses the second method of ClassPathResource<br>&gt;&gt; (getInputStream()) to get the content of the resource. In the case of Tomcat<br>
&gt;&gt; (and probably some other environments), it seems that<br>&gt;&gt; &gt;&gt;&gt;&gt; the classloader (Tomcat&#39;s classloader) is using a cache. So the<br>&gt;&gt; InputStream returned doesn&#39;t reflect the current state of the resource.<br>
&gt;&gt; &gt;&gt;&gt;&gt; Long story short: the agent is notified about a change in the<br>&gt;&gt; resource, but the change is never applied to the kbase because the kbuilder<br>&gt;&gt; is unable to get it :P<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt; Solutions:<br>&gt;&gt; &gt;&gt;&gt;&gt; The first solution is not to use classpath resources :). You can use<br>&gt;&gt; just url resources like http:// or file:/. But honestly, when you have<br>
&gt;&gt; your rules inside your webapp, it is much<br>&gt;&gt; &gt;&gt;&gt;&gt; more comfortable and even manageable to avoid the use of real paths.<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; What I was thinking about (I already have a working prototype) is to<br>
&gt;&gt; create a new Resource type for these cases. This resource type will let you<br>&gt;&gt; define your resources present in your<br>&gt;&gt; &gt;&gt;&gt;&gt; classpath as usually but it will translate them to URL Resource<br>
&gt;&gt; internally.<br>&gt;&gt; &gt;&gt;&gt;&gt; So, in the example above:<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; &lt;drools:resource type=&quot;DRL&quot; source=&quot;*URLClasspath*:simple.drl&quot;/&gt;<br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; is going to be translated (internally and in a transparent way) to<br>&gt;&gt; something like:<br>&gt;&gt; file:/usr/local/apache-tomcat-7/webapps/MyWebapp/WEB-INF/simple.drl.<br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; Opinions?<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; Esteban Aliverti<br>
&gt;&gt; &gt;&gt;&gt;&gt; - Developer @ <a href="http://www.plugtree.com">http://www.plugtree.com</a> &lt;<a href="http://www.plugtree.com">http://www.plugtree.com</a>&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; - Blog @ <a href="http://ilesteban.wordpress.com">http://ilesteban.wordpress.com</a><br>
&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;&gt; _______________________________________________<br>&gt;&gt; &gt;&gt;&gt;&gt; rules-dev mailing list<br>&gt;&gt; &gt;&gt;&gt;&gt; <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&gt;<br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt;&gt; rules-dev mailing list<br>&gt;&gt; &gt;&gt;&gt; <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&gt;<br>
&gt;&gt; &gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; --<br>&gt;&gt; &gt;&gt;&gt; - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a><br>&gt;&gt; &gt;&gt;&gt; - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
&gt;&gt; &gt;&gt;&gt; - Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; - Salatino &quot;Salaboy&quot; Mauricio -<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; --<br>&gt;&gt; &gt;&gt;&gt; - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a><br>&gt;&gt; &gt;&gt;&gt; - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
&gt;&gt; &gt;&gt;&gt; - Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>&gt;&gt; &gt;&gt;&gt;<br>&gt;&gt; &gt;&gt;&gt; - Salatino &quot;Salaboy&quot; Mauricio -<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-dev mailing listrules-dev@lists.jboss.orghttps://<a href="http://lists.jboss.org/mailman/listinfo/rules-dev">lists.jboss.org/mailman/listinfo/rules-dev</a><br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-dev mailing list<br>&gt;&gt; <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
&gt;&gt;<br>&gt;&gt;<br>&gt; <br>&gt; <br>&gt; -- <br>&gt;  - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a><br>&gt;  - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
&gt;  - Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>&gt; <br>&gt;  - Salatino &quot;Salaboy&quot; Mauricio -<br></div>