PackageBuilderConfiguration conf = new PackageBuilderConfiguration( loader1 );
PackageBuilder builder = new PackageBuilder( conf );
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
// must set the classloader for rulebase conf too
RuleBaseConfiguration rbconf = new RuleBaseConfiguration( loader1 );
RuleBase ruleBase = RuleBaseFactory.newRuleBase( rbconf );
Package pkg = SerializationHelper.serializeObject( builder.getPackage() );
ruleBase.addPackage( pkg );
// ruleBase = SerializationHelper.serializeObject(ruleBase);
StatefulSession wm = ruleBase.newStatefulSession();
wm.insert( cheeseClass.newInstance() );
wm.fireAllRules();
// Creates second class loader and use it to load fact classes
ClassLoader loader2 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" )},
this.getClass().getClassLoader() );
cheeseClass = loader2.loadClass( "org.drools.Cheese" );
conf = new PackageBuilderConfiguration( loader2 );
builder = new PackageBuilder( conf );
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
rbconf = new RuleBaseConfiguration( loader2 );
ruleBase = RuleBaseFactory.newRuleBase( rbconf );
pkg = SerializationHelper.serializeObject( builder.getPackage() );
ruleBase.addPackage( pkg );
// ruleBase = SerializationHelper.serializeObject(ruleBase);