1
我正在嘗試對我的動態Web應用程序使用簡單的Drools規則。我創建了我的servlet,現在試圖整合我的規則。但它給我的錯誤在這行在Glassfish服務器上使用Drools
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
java.lang.NoSuchMethodError: org.drools.util.ChainedProperties.<init>(Ljava/lang/String;Ljava/lang/ClassLoader;Z)V
at org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:395)
at org.drools.RuleBaseConfiguration.<init>(RuleBaseConfiguration.java:251)
at org.drools.common.AbstractRuleBase.<init>(AbstractRuleBase.java:147)
at org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:160)
at org.drools.reteoo.ReteooRuleBase.<init>(ReteooRuleBase.java:137)
at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:87)
at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:75)
at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:38)
at server.HelloServlet.runRules(HelloServlet.java:148)
at server.HelloServlet.NewRule(HelloServlet.java:181)
at server.HelloServlet.doGet(HelloServlet.java:82)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
,在這裏我Helloservlet.java類
@WebServlet( 「/ HelloServlet」) 公共類HelloServlet延伸的HttpServlet { 私有靜態最後的serialVersionUID長= 1升;
@EJB HelloBean bean;
@PersistenceUnit
EntityManagerFactory emf;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.print("<html><body><title>servlet page</title>");
out.print("<h1> " +request.getServletPath() + "</h1>");
out.println("<h2>" + bean.sayHello("nabiyin") + "</h2>");
MyUser user=(MyUser)emf.createEntityManager().createQuery("select u from MyUser u").getResultList().get(0);
try {
NewRule();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("HATAAAAA");
e.printStackTrace();
}
out.print("age: " + user.getAge());
if (user.getAge()<23) {
out.println("hello");
}
out.print("</html></body>");
}
public void runRules(String[] rules, Object... facts)
throws Exception
{
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
PackageBuilder builder = new PackageBuilder();
for(String ruleFile : rules)
{
System.out.println("Loading file: "+ruleFile);
builder.addPackageFromDrl(
new InputStreamReader(
this.getClass().getResourceAsStream(ruleFile)));
}
Package pkg = builder.getPackage();
ruleBase.addPackage(pkg);
WorkingMemory workingMemory
= ruleBase.newStatefulSession();
for(Object fact : facts)
{
System.out.println("Inserting fact: "+fact);
workingMemory.insert(fact);
}
workingMemory.fireAllRules();
}
public void NewRule()
throws Exception
{
System.out.println("New rule started");
Number n1=3 , n2=1, n3=4 , n4=1 ,n5=5;
new HelloServlet().runRules(
new String[]{"model/NewRule.drl"},
n1,n2,n3,n4,n5);
System.out.println("New rule finisheds");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}