Hi,

For specific reasons we want to use a special classloader (JCL, 
http://jcloader.sourceforge.net<http://jcloader.sourceforge.net/>) to load jar 
files that contain fact classes and jessML files. We use Rete.setClassLoader() 
to make Jess aware of this classloader.

One characteristic of JCL is that it loads the jar file as stream so that it is 
not aware of the real location/URL of the underlying jar file. Therefore it is 
not possible to return a proper URL when jclClassLoader.getResource() is called 
for a jessML file that is part of the jar file (it always returns null). On the 
other hand jclClassLoader.getResourceAsStream() works fine.

Using this classloader with Jess works fine except that loading a jessML file 
from the classloader fails. The reason is that Rete.batch() internally uses 
classloader.getResource() to get the URL of the given file (which in this case 
returns null). If that URL is null an exception is thrown, if not a stream is 
opened; see Batch.findDocument(Rete engine, String filename, String charset).

I wonder why Jess doesn't try to use the classloader.getResourceAsStream() as 
another alternative before throwing the exception. I tried this and changed the 
lines to:

            URL u = engine.getResource(filename);
            InputStream is;
            if (u != null) {
                is = u.openStream();
            } else {
                try {
                    is = engine.getClassLoader().getResourceAsStream(filename);
                }
                catch (Exception e2) {
                    throw new JessException("batch", "Cannot open file", e);
                }
            }

            fis = new PushbackReader(new InputStreamReader(is, charset));

In my first simple tests this works very well. Do you see any objections? Could 
this be integrated into the next release of Jess? Or are there any other 
possibilities to achieve the described functionality without changes in Jess 
source code?

Thanks!
Michael

Reply via email to