On 11/14/05, Mark Stang <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I am trying to load a business rule file from a resource:
>
> businessRules =
> RuleBaseLoader.loadFromUrl(BusinessLayer.class.getResource("
> businessrules.drl"));
>
> Where the file is embedded in a .jar. Do I have to do anything useful?
>
> The getResource is returning a null URL.
>Given that getResource is a JSE call, it's not /really/ a Drools question ... but ... I haven't tried to pull a resource out of a JAR recently, but my recollection is that getResource() worked as long as the JAR was on the classpath, but gave a URL that couldn't be read easily, whereas getResourceAsStream() worked in the same conditions and allowed easy reading. So you /could/ try getResourceAsStream(). If you're getting a null resource, it implies it's not finding it, so either the JAR isn't in your classpath, or I'm misremembering how getResource() interacts with JARs, or, finally, you've got a classloader problem. You can start poking around in BusinessLayer.class.getClassLoader() if you like. Finally, if you're doing this in a JEE environment, I'd recommend Thread.currentThread().getContextClassloader() as your classloader of choice. I haven't heard any reason to use that for JSE, but AFAIK, it might still be a good choice. Hope some aspect of this is helpful. - Geoffrey -- Geoffrey Wiseman
