使用Maven在OSX上出现SWT错误

时间:2014-05-10 16:28:10

标签: java maven swt jface

我制作了一个示例应用程序,我想使用maven在osx下测试swt。我已经阅读了数百篇文章并在主线程上创建了显示,但应用程序抛出相同的异常。

你可以查看我的pom文件和my sample application吗?

的pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>asdf.abcd</groupId>
    <artifactId>b</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>example</name>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jface</groupId>
            <artifactId>jface</artifactId>
            <version>3.9.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <arguments>
                        <argument>-d64</argument>
                        <argument>-XstartOnFirstThread</argument>
                        <argument>-classpath</argument>
                    </arguments>
                    <mainClass>standalone.App</mainClass>
                    <addClasspath>true</addClasspath>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>standalone.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>

    </build>

</project>

异常:

    ###Thread name: standalone.App.main() Thread[standalone.App.main(),5,standalone.App] <-- debug message


***WARNING: Display must be created on main thread due to Cocoa restrictions.
[WARNING] 
java.lang.reflect.InvocationTargetException
    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.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.widgets.Display.error(Unknown Source)
    at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
    at org.eclipse.swt.widgets.Display.create(Unknown Source)
    at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
    at standalone.App.main(App.java:66)
    ... 6 more

感谢您的想法和时间!

1 个答案:

答案 0 :(得分:2)

在MAc OS X上运行SWT应用程序时,需要指定-XstartOnFirstThread选项。