Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reflection 查找RCP应用程序的显示_Reflection_Swt_Eclipse Rcp_Classloader - Fatal编程技术网

Reflection 查找RCP应用程序的显示

Reflection 查找RCP应用程序的显示,reflection,swt,eclipse-rcp,classloader,Reflection,Swt,Eclipse Rcp,Classloader,我正在编写一个启动GUI应用程序的测试框架。为了能够在SWT应用程序中测试这个GUI,我需要知道它的显示。通常,这个显示是由另一个类加载器加载的,因此我使用swt显示类的findDisplay(线程t)方法通过反射来完成这个任务。我的代码如下所示: Thread[] threads = new Thread[10]; Thread.enumerate(threads); Object foundObject = null; for (Thread t : Arrays.asList(thread

我正在编写一个启动GUI应用程序的测试框架。为了能够在SWT应用程序中测试这个GUI,我需要知道它的显示。通常,这个显示是由另一个类加载器加载的,因此我使用swt显示类的findDisplay(线程t)方法通过反射来完成这个任务。我的代码如下所示:

Thread[] threads = new Thread[10];
Thread.enumerate(threads);
Object foundObject = null;
for (Thread t : Arrays.asList(threads)){
    foundObject = null;
    Class<?> clazz = t.getContextClassLoader().loadClass("org.eclipse.swt.widgets.Display");
    final Method method = clazz.getMethod("findDisplay", Thread.class);
    foundObject = method.invoke(null, new Object[] {t});
    if (foundObject != null) {
        System.out.println("yeah, found it!");
        break;
    }
}
Thread[]threads=新线程[10];
枚举(线程);
objectfoundobject=null;
for(线程t:Arrays.asList(线程)){
foundObject=null;
Class clazz=t.getContextClassLoader().loadClass(“org.eclipse.swt.widgets.Display”);
final方法=clazz.getMethod(“findDisplay”,Thread.class);
foundObject=method.invoke(null,新对象[]{t});
if(foundObject!=null){
System.out.println(“是的,找到了!”);
打破
}
}
在我看来,这应该可以在当前线程组中找到每一个Display类型的对象。然而,我没有得到任何关于texteditor RCP示例的信息,尽管GUI已经完美启动


你知道哪里出了问题,或者我如何以合理的方式调试它吗?

我知道了主要问题是什么:ContextClassloader与实际加载类的classloader无关


为了解决我的问题,我在RCP程序的层次结构和我的框架的层次结构中使用了类加载器来加载swt显示类。这可以通过使用java扩展类加载器实现。(我无法使用应用程序类加载器,因为我的RCP应用程序不能将其作为父级使用,我还不知道为什么)当时只需将swt.jar添加到java.ext.dirs属性中即可。

如果您使用的是Eclipse RCP,那么您可能可以使用:

PlatformUI.getWorkbench().getDisplay()


有什么特别的原因可以解释为什么在有很多测试框架的情况下还要构建另一个测试框架?有商业框架可用,但是SWTBot Eclipse项目非常好,可以在EPL下使用。实际上,我正在使用的框架是abbot.swt之上的东西,我认为它与SWTBot相当。但整个系统将是一个“集成”的系统,可以处理多种不同的应用程序类型,而不仅仅是SWT应用程序。所以我对如何启动测试中的应用程序有些限制。