[rules-users] java.lang.NoClassDefFoundError

Hemanth kumar hemanth at saha.in
Thu Oct 29 05:20:16 EDT 2009


hi iam working on sample drools project.

In that i was dynamically loading a fact ang running the rule engine.
Based on the reply from the people of y previous post i have made some
modifications.

In the Eclipse editor it works fine.but when i call it externally it is
throwing the error.I guess class path was recognised by the ruleengine

------------------------------------------------------------------------------------
java class


static String path="C:\\Program Files\\Apache Software Foundation\\Tomcat
6.0\\webapps\\JStudio\\WEB-INF\\classes\\";
try{
			
			System.out.println("Initializing Fact....");
			
			URL[] urls = new URL[]{ new URL("file://"+path) };
	 		ClassLoader loader =  new URLClassLoader(urls);
	 		Class clazz  = loader.loadClass("test.Message");
	 			            
	 		Object factObj = clazz.newInstance();
	 		
	 		
	 		Method method = clazz.getMethod("setMessage", new
Class[]{String.class});
	 		Method method1 = clazz.getMethod("getMessage");
	 		//System.out.println("facts loaded\n");
	
	 		method.invoke(factObj, new Object[]{"Hello"});
			 			
	 		System.out.println("initializing packageBuilder");
	 		
	 		PackageBuilderConfiguration config = new PackageBuilderConfiguration();
	 		config.setClassLoader(loader);
	 		
			KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(config);
			
			System.out.println("finding Rule");
	       
kbuilder.add(ResourceFactory.newClassPathResource("test/Sample.drl"),ResourceType.DRL);
	
	        if (kbuilder.hasErrors())
	        	  throw new RuntimeException("Unable to compile rules. " + 
	        			    kbuilder.getErrors().toString());

	
	        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(new
RuleBaseConfiguration(loader));
	
	        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

        	StatelessKnowledgeSession session =
kbase.newStatelessKnowledgeSession();

        	System.out.println("running rule....... \n");
     		session.execute(factObj);
        	
     		System.out.println("\nend...\n");
     		
        }
        catch (Throwable t) {
			t.printStackTrace();				
		}

---------------------------------------------------------------------------------
tomcat output console


http://www.nabble.com/file/p26109542/console.PNG console.PNG 


suggest me any ideas

Hemanth

-- 
View this message in context: http://www.nabble.com/java.lang.NoClassDefFoundError-tp26109542p26109542.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list