首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • DRools + SWT/JFace: Unable to create view: org/drools/WorkingMemory
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-02-09 11:22:36 楼主
    我在尝试用SWT/JFace做RCP Based DRools Application, 但是在Run As "Eclipe Application" 的时候调用DRools的View中出现了错误信息"Unable to create view: org/drools/WorkingMemory".

    我的相关View代码如下, 如果把    workingMemory = ruleBase.newStatefulSession();注释掉就没有这个错误, 哪位知道这是为什么?

    我的这段代码的主要目的是尝试在按一个Button后调用"Hello World" DRools sample.


    package com.configurator.rcpexample2.intro;

    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.ui.part.ViewPart;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.widgets.Button;

    import java.io.InputStreamReader;
    import java.io.Reader;
    import org.drools.RuleBase;
    import org.drools.RuleBaseFactory;
    import org.drools.WorkingMemory;
    import org.drools.compiler.PackageBuilder;
    import org.drools.rule.Package;

    import com.configurator.rcpexample2.intro.Message;

    public class TreeView extends ViewPart {

    public static final String ID = "com.configurator.rcpexample2.intro.TreeView"; // TODO Needs to be whatever is mentioned in plugin.xml

    private Composite top = null;

    private Composite composite = null;

    private Composite composite1 = null;

    private Button button = null;

    private Button button1 = null;

    public static RuleBase ruleBase;  //  @jve:decl-index=0:
    public static WorkingMemory workingMemory;
    public static Message message = null;  //  @jve:decl-index=0:

    public void createPartControl(Composite parent) {
    // TODO Auto-generated method stub
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    top = new Composite(parent, SWT.NONE);
    top.setLayout(gridLayout);
    createComposite();
    createComposite1();
    }

    public void setFocus() {
    // TODO Auto-generated method stub

    }

    /**
    * This method initializes composite
    *
    */
    private void createComposite() {
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    composite = new Composite(top, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(gridData);
    button = new Button(composite, SWT.NONE);
    button.setText("Botton 1");
    button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
    public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
    System.out.println("widgetSelected()"); // TODO Auto-generated Event stub widgetSelected()
    }
    });

    button.addMouseListener(new org.eclipse.swt.events.MouseAdapter() {

    public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
    try{
    firerule();
      } catch (Throwable t) {
                t.printStackTrace();
            }

      System.out.println("mouseUp()"); // TODO Auto-generated Event stub mouseUp()
    }
    });
    }

    /**
    * This method initializes composite1
    *
    */
    private void createComposite1() {
    GridData gridData1 = new GridData();
    gridData1.grabExcessHorizontalSpace = true;
    gridData1.horizontalAlignment = GridData.FILL;
    gridData1.verticalAlignment = GridData.FILL;
    gridData1.grabExcessVerticalSpace = true;
    composite1 = new Composite(top, SWT.NONE);
    composite1.setLayout(new GridLayout());
    composite1.setLayoutData(gridData1);
    button1 = new Button(composite1, SWT.NONE);
    button1.setText("Botton 2");
    }

      /**
        * Please note that this is the "low level" rule assembly API.
        */
    private static RuleBase readRule() throws Exception {
    //read in the source
    Reader source = new InputStreamReader( TreeView.class.getResourceAsStream( "/Sample.drl" ) );

    //optionally read in the DSL (if you are using it).
    //Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );

    //Use package builder to build up a rule package.
    //An alternative lower level class called "DrlParser" can also be used...

    PackageBuilder builder = new PackageBuilder();

    //this wil parse and compile in one step
    //NOTE: There are 2 methods here, the one argument one is for normal DRL.
    builder.addPackageFromDrl( source );

    //Use the following instead of above if you are using a DSL:
    //builder.addPackageFromDrl( source, dsl );

    //get the compiled package (which is serializable)
    Package pkg = builder.getPackage();

    //add the package to a rulebase (deploy the rule package).
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    return ruleBase;
    }

    private static boolean firerule() throws Exception {

            try {
                 
            //load up the rulebase
                ruleBase = readRule();
               
                workingMemory = ruleBase.newStatefulSession();
               
               
                //go !
                message = new Message();
                message.setMessage(  "Hello World" );
               
                message.setStatus( Message.HELLO );
                /*
                workingMemory.insert( message );
                workingMemory.fireAllRules(); 
                */
               
            } catch (Throwable t) {
           
                t.printStackTrace();
               
            }
           
    return true;

    }
    }

    View中的错误信息:

    java.lang.NoClassDefFoundError: org/drools/WorkingMemory
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
    at java.lang.Class.getConstructor0(Class.java:2671)
    at java.lang.Class.newInstance0(Class.java:321)
    at java.lang.Class.newInstance(Class.java:303)
    at ....
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-02-15 13:43:531楼 得分:0
    没有在classpath中找到Drools的jar包
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-04-30 18:59:112楼 得分:0
    等待牛人来答.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-01 17:10:383楼 得分:0
    接分先!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-09 15:06:164楼 得分:0
    发表于:2008-05-09 13:40:51 楼主

    北京思源培训中心(http://www.ciitc.com)专业做软件开发技术的培训;由于课程培训需要,长年高薪诚聘兼职讲师,欢迎计算机及相关专业的高校老师、研究生、博士生应聘   
    基本要求如下:
    l    本科以上学历,计算机或相关专业毕业。
    2    具有实际相关工作经验,从事过软件开发或系统管理工作。
    3    语言表达清楚、流畅、逻辑思维清晰,英语听说良好。
    4    诲人不倦,有高度的责任感、敬业精神和团队意识。
    5    注重仪表,具有随机应变的能力。
    6    具有一定的教学经验,从事过教学/培训业务者优先考虑。

    精通应聘职位的某一部分课程内容,如下述编程语言或系统的一种或几种:
    1.    编程语言:C++, VC++,VB.NET,C#, PowerBuilder, Delphi, Java,
      Matlab , C++Builder
    2.    数据库系统:SQL Server2000, SQL Server2005, Oracle,DB2,MySql
    3.    网站编程:Marcomedia, HTML, Altova XML Suite,ASP, JSP, J2EE, J2SE,
        PHP,ASP.NET,VB.NET, ColdFusion,ajax
    4.    操作系统:Unix, Linux,Linux环境下嵌入式开发技术,Sun Solaris,IBM AIX
    5.      办公软件:OFFICE(EXCEL、WORD、POWERPOINT)
    6.      多媒体制作:Authorware7.0  , Director MX 2004
    7.      图形动画类:Photoshop, Illustrator, CorelDRAW, FreeHand, 
    Flash ActionScript高级编程,3DMAX,AutoCAD2007 ,Maya
    具有下述任何一种或几种国际IT认证证书者优先考虑:
    1.    微软认证证书MCP / MCSA / MCSE / MCDBA / MCSD
    2.    SUN Java认证证书
    3.    Oracle认证证书
    4.    Macromedia认证证书
    5.    Linux认证证书
    6.    CIW (Certified Internet Webmaster) Associate/Professional/Master认证证书

    有意者请把简历发到如下地址:abc@ciitc.com  QQ:174629429  MSN:bjcosun@hotmail.com
    http://www.ciitc.com



    问题点数:20 回复次数:0 显示所有回复显示星级回复显示楼主回复 修改 删除 举报 引用 回复 
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved