The typical use case would be that you recompile the classes if one of
the following conditions is true:
- your app starts
- you want to recompile because the rules have changed
To achieve this, access the kb through a wrapper that caches the kb (as
instance variable) with lazy initialization, and reset this variable to
null if you want to trigger recompilation.
If you want to keep the kb between application startups, try the
following (I have not tried this, but it should work): serialize the kb.
To deserialize, you will need to use the custom classloader as typically
the working directory is outside the normal application classloader
classpath. For binary serialization, overridding resolveClass in
ObjectInputStream should do the trick (your kb must also implement
Serializable)!. I am not sure how it works fo XMLDecoder, but this
shoudl be possible as well.
Or, even simpler, store the package name of the implementation class in
a config file, and use a URLClassLoader to load the KB class from there
and instantiate it with newInstance() !
Hope this helps, Jens