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