JavaFX - 由 : java. lang.UnsupportedOperationException : Unable to open DISPLAY? 引起

标签 java linux javafx deb

我正在使用 jdeb 为基于 debian 的发行版生成我的 .deb 安装程序。应用程序安装没有错误,但是当我尝试运行 service myapp start 它失败并出现以下异常(应用程序继续运行但 FX 场景从未显示):

2016-12-30 11:19:51,468 [main] INFO  o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 0
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
    at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:68)
    at com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
    at com.sun.glass.ui.Application.run(Application.java:146)
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:695)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)

与此同时,如果我简单地运行 sudo/etc/init.d/myapp start,它会正常运行并且显示我的第一个 FX 场景。

下面是我对 jdeb 的 maven 配置:

<plugin>
    <artifactId>jdeb</artifactId>
    <groupId>org.vafer</groupId>
    <version>1.5</version>

    <executions>
        <execution>
            <id>appassembler</id>
            <phase>package</phase>
            <goals>
                <goal>jdeb</goal>
            </goals>
            <configuration>
                <deb>${project.build.directory}/${project.build.finalName}.deb</deb>
                <snapshotExpand>false</snapshotExpand>
                <!-- expand "SNAPSHOT" to what is in the "USER" env variable -->
                <snapshotEnv>USER</snapshotEnv>
                <verbose>true</verbose>
                <controlDir>${basedir}/src/deb/control</controlDir>
                <dataSet>
                    <data>
                        <src>${project.build.directory}/${project.build.finalName}-uber.jar</src>
                        <type>file</type>
                        <mapper>
                            <type>perm</type>
                            <prefix>/opt/stone/${project.build.finalName}</prefix>
                            <filemode>755</filemode>
                            <user>root</user>
                            <group>root</group>
                        </mapper>
                    </data>
                    <data>
                        <src>src/deb/upstart/${project.build.finalName}.conf</src>
                        <type>file</type>
                        <mapper>
                            <type>perm</type>
                            <prefix>/opt/stone/${project.build.finalName}</prefix>
                            <filemode>755</filemode>
                            <user>root</user>
                            <group>root</group>
                        </mapper>
                    </data>
                </dataSet>
            </configuration>
        </execution>
    </executions>
</plugin>

这是我的安装后脚本:

#!/bin/bash

echo Creating symblink...
sudo ln -s /opt/stone/acs/acs-uber.jar /etc/init.d/acs

echo Creating service...
sudo update-rc.d acs start 98 5 .

echo Starting service...
sudo service acs restart

最佳答案

引用来自其他地方的答案,该答案对我有用,在 Ubuntu 上以 javafx 为根... 也许这可以帮助别人。我和你有同样的问题,但对于普通用户。假设我想使用用户帐户 foo 启动 firefox。我以 bar 身份登录:

[bar@localhost ~]$ sudo -u foo -H firefox

遗憾的是,该命令失败并出现与问题中相同的错误(即未指定协议(protocol)且无法打开显示)

我的解决方案是简单地将用户 foo 添加到 X 服务器的授权访问列表中。

xhost si:localuser:foo

就是这样,然后我可以使用 sudo 和用户 foo 启动 Firefox(和其他 X 应用程序)。

关于JavaFX - 由 : java. lang.UnsupportedOperationException : Unable to open DISPLAY? 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41397687/

相关文章:

linux - 在 bash 中删除另一个文件中存在的内容

linux - Trac 在哪里存储它的环境信息

linux - 将文件行排列成表格形式

java - 我应该如何分隔以下三个字符串?

java - Gradle:从自定义任务中调用 ant

java - Android 图像上的文字

java - 在 JavaFX 中使用鼠标滚轮缩放

javafx GridPane 检索特定的单元格内容

java - 如何从用作 WatchService 的线程调用主线程中的方法?

java - 如何将Xlloop集成到JAVA Web服务器中?