2015-12-09 99 views
1
import org.openl.rules.runtime.RulesEngineFactory; 
import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.Node; 
import org.w3c.dom.NodeList; 
// Action rule 
public static String ActionRule(ClassRule classRule, String gender, 
     String marialStatus) throws IOException { 
    // TODO Auto-generated method stub 
    // define the interface 
    RulesEngineFactory<?> rulesFactory = new RulesEngineFactory<Object>("D:/GreetingCustomer.xlsx"); 
    Object rules = rulesFactory.newInstance(); 
    Class<?> clazz = rulesFactory.getInterfaceClass(); 

    // define params 
    String Gender = gender; 
    String MarialStatus = marialStatus; 

    // define info of rule method 

    int iNumOfParams = classRule.getListItem().size(); 
    // define param types 
    Class[] paramClases = new Class[iNumOfParams]; 
    paramClases[0] = String.class; 
    paramClases[1] = String.class; 

    // set param value 
    Object[] params = new Object[iNumOfParams]; 
    params[0] = Gender; 
    params[1] = MarialStatus; 

    String result = ""; 
    try { 
     Method method = clazz.getMethod(classRule.getRuleName(), 
       paramClases); 
     System.out.println("* Executing OpenL rules...\n"); 
     // invoke method 
     Object interestAmount = method.invoke(rules, params); 
     if (interestAmount != null) { 
      System.out.println("Siri Say: " + interestAmount); 
      result = interestAmount.toString(); 
     } else { 
      System.out.println("Wrong input value"); 
      result = "Wrong input value"; 
     } 
    } catch (NoSuchMethodException e) { 
    } catch (InvocationTargetException e) { 
    } catch (IllegalAccessException e) { 
    } 
    return result; 
} 

當我打電話的ActionRule方法Eclipse中給我的錯誤信息: Error錯誤拋出java.lang.ClassNotFoundException

我加org.openl.rules-5.16.2.jar到Libraies但它仍然不工作。我不知道爲什麼?有什麼人有解決方案來解決這個問題? 非常感謝。

+0

後的異常堆棧跟蹤,如代碼格式的文本,在你的問題。請尊重Java命名約定,並且不要忽略異常。 –

+0

您的服務器沒有類org.openl.rules.runtime.RulesEngineFactory(在jar中)? –

回答

1

這不是日食,它缺少庫,它是tomcat。確保您的部署已將org.openl.rules-5.16.2.jar放置到您的Web應用程序的WEB-INF/lib中。

之後,重新啓動Tomcat或重新部署應用

+0

耶!我將org.openl.rules-5.16.2.jar添加到WEB-INF/lib中,並且工作正常。非常感謝 – Nasper

+0

如果你接受了答案,那麼我會很好:-) – Jan

+0

是的。我接受了答案。對不起,忘了吧:D – Nasper

相關問題