簡體   English   中英

使用Composites with Shell for eclipse with maven

[英]using Composites with Shell for java in eclipse with maven

我在eclipse中有一個使用一些復合材料的java maven項目,但是我在創建一個主方法來啟動我的小部件時遇到了麻煩。

我添加了以下依賴項:

    <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)

您正在包含不用於普通SWT應用程序的Eclipse RAP版本的SWT。

刪除RAP依賴項,只使用普通的SWT。

您似乎應該為操作系統指定SWT依賴項。 例如,這里是OS X的依賴:

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

這里列出了其他操作系統的依賴關系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM