【问题标题】:Run a java Class inside an interface在接口内运行 java 类
【发布时间】:2015-05-15 16:40:48
【问题描述】:

您好,我正在开发一个 Eclipse RCP 项目,我需要通过将实例添加到按钮 Selected Listener 来从 ViewPart 的类中运行一个函数,我在函数中使用 Gate NLP,所以在运行项目后我得到很多例外,这是其中的一部分:

org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: gate/util/GateException
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:857)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:119)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:333)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:254)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:102)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:71)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:53)
    at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:949)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:633)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$6.run(PartRenderingEngine.java:526)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    ....
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NoClassDefFoundError: gate/util/GateException
    at segmentation.View.createPartControl(View.java:258)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityView.createPartControl(CompatibilityView.java:174)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    ... 84 more
Caused by: java.lang.ClassNotFoundException: gate.util.GateException cannot be found by Segmentation_1.0.0.qualifier
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 93 more

这就是我使用课程的方式:

btnSegmenter.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SegClass s = new SegClass();

            if ((!(text_2.getText().isEmpty())) && (!(text_1.getText().isEmpty())))
                    {
                    try {
                        s.Segmenter(text_3.getText(), text_2.getText());
                    } catch (GateException | IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    }


        }
    });

所以请帮助我找到另一种方式来运行我的课程,谢谢!

【问题讨论】:

  • NoClassDefFoundError总是关于在编译时存在但在运行时缺失的类。
  • 你是什么意思存在于编译时,但在运行时缺失?我实际上在一个简单的java项目上测试了代码,然后我创建了一个类的实例并在按下按钮后尝试在那里运行它你能告诉我问题出在哪里吗?
  • 类加载器在运行时找不到包含该类的 JAR 或目录。换句话说,确保gate.util.GateException 在类路径中。

标签: java eclipse gate


【解决方案1】:

您是否将“分段”相关的 jar 或文件添加到插件运行时。
Plugin.xml ->运行时->类路径->添加->

【讨论】:

  • 打开你的 plugin.xml 文件 Plugin.xml ->Run-time->class path-> add->
  • stackoverflow.com/questions/5744520/… 我发现这个真的很有用 谢谢大家的帮助
  • 使用 Import>File System 将 jar 文件导入到您的插件项目中,例如在 /lib 目录中。使用“添加...”将 jars 添加到 plugin.xml>Runtime 选项卡的类路径部分。使用“新建...”添加“。”图书馆回来(当然没有引号)。确保您的二进制构建在 plugin.xml>Build 选项卡上导出新的 jar 文件。保存项目,使用上下文菜单>PDE 工具>更新类路径将 jar 正确添加到 eclipse 项目类路径中。我用过这个,但我有一个问题,我必须添加 New..." 才能为每个 jar 添加 "." 库吗??
猜你喜欢
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 2011-08-01
  • 2013-01-04
  • 1970-01-01
  • 2013-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多