【问题标题】:using Composites with Shell for java in eclipse with maven在带有 maven 的 Eclipse 中使用 Composites with Shell for java
【发布时间】:2015-03-07 13:55:38
【问题描述】:

我在 Eclipse 中有一个使用一些 Composites 的 java maven 项目,但是在创建启动小部件的 main 方法时遇到了问题。

我添加了以下依赖:

    <dependency>
        <groupId>org.eclipse.rap</groupId>
        <artifactId>org.eclipse.rap.rwt</artifactId>
        <version>3.0.0-M5</version>
    </dependency>

这是我的主要方法(MainWindow 是我的复合方法)

public static void main(String[] args){
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(450,256);
    shell.setText("My Title");
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    MainWindow window = new MainWindow(shell, SWT.ALL);
    shell.open();
    while(!shell.isDisposed()){
        if(!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}

如果我尝试在 Eclipse 中运行此应用程序,我会收到以下错误:

Exception in thread "main" java.lang.IllegalStateException: No context available outside of the request processing.
    at org.eclipse.rap.rwt.internal.service.ContextProvider.getContext(ContextProvider.java:95)
    at org.eclipse.rap.rwt.internal.service.ContextProvider.getUISession(ContextProvider.java:183)
    at org.eclipse.rap.rwt.internal.lifecycle.LifeCycleUtil.setSessionDisplay(LifeCycleUtil.java:24)
    at org.eclipse.swt.widgets.Display.<init>(Display.java:275)

如果我在将其编译为 jar 后执行此操作,则会得到:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Layout
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

如何让我的应用程序启动? 谢谢

更新:

通过在构建插件中使用 jar-with-dependency 解决了 NoClassdefFound。

No Context available 错误现在在两个执行(cmd 和 eclipse)上都会弹出

【问题讨论】:

  • 您真的想使用 Eclipse RAP 还是只使用 SWT?
  • 啊!就是这样。我已经添加了一些依赖项。谢谢。发布答案。我刚刚删除了 rap 依赖项并启动了

标签: java eclipse maven dependencies swt


【解决方案1】:

您将包含不用于普通 SWT 应用程序的 Eclipse RAP 版本的 SWT。

删除 RAP 依赖项,只使用普通 SWT。

【讨论】:

    【解决方案2】:

    似乎您应该为您的操作系统指定 SWT 依赖项。例如这里是 OS X 的依赖:

    <dependency>
        <groupId>org.eclipse.swt</groupId>
        <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
        <version>4.4</version>
    </dependency>
    

    Here 其他操作系统的依赖项列表。

    【讨论】:

    • 我仍然得到相同的 NoClassDef
    • 检查 Eclipse 是否加载了此依赖项或尝试从终端构建和运行应用程序。
    • 从终端构建和运行时发生 NoClassDef 错误。 IllegalStateExcpetion(没有可用的上下文)在 eclipse 中运行时出现
    • 更新:通过在构建插件中使用 jar-with-dependency 解决了 noClassdefFound。但是现在在两个执行(cmd 和 eclipse)上都会弹出 No Context available 错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多