You also have to get the resource name right (sorry if this is obvious)
...getResource("businessrules.drl") looks for the file adjacent to the
BusinessLayer class i.e. if the class is foo.bar.BusinessLayer it will look
for <jar file root>/foo/bar/businessrules.drl.
It looks for the drl file relative to the BusinessLayer class because you
called getResource on that class.
If you want a file at the root of the jar you use
...getResource("/businessrules.drl").
So you may want to take a look in the jar to check that the resource name
is abosulte/relative as required.
Adrian.
Geoffrey Wiseman
<geoffrey.wiseman To:
[email protected]
@gmail.com> cc:
Subject: Re: [drools-user] How
to find a .drl
14/11/2005 07:21
Please respond to
user
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
**********************************************************************
This e-mail and any attachment is intended for the named addressee(s) only, or
person authorised to receive it on their behalf. The content should be treated
as confidential and the recipient may not disclose this message or any
attachment to anyone else without authorisation. Unauthorised use, copying or
disclosure may be unlawful. If this transmission is received in error please
notify the sender immediately and delete this message from your e-mail system.
Any view expressed by the sender of this message or any attachment may be
personal and may not represent the view held by First Choice Holidays PLC and
its subsidiaries. All electronic transmissions to and from First Choice are
recorded, may be monitored and are scanned for viruses and content. E-mails
containing viruses will be deleted without notification. Whilst we maintain
virus checks on inbound e-mails we accept no liability for viruses or other
material introduced with this message.
All companies form part of the First Choice Holidays PLC group of companies.
First Choice Holidays PLC Company Registration No: 48967 (England)
Registered Office: First Choice House, London Road, Crawley, WestSussex RH10 9GX
**********************************************************************