Linux Java 无法使用“localhost:10.0”作为 DISPLAY 变量的值连接到 X11 窗口服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10165761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable
提问by Elteroooo
I have a script using java to connect to display X11 in the port 10.0 at localhost
我有一个使用 java 连接到本地主机的端口 10.0 中显示 X11 的脚本
but i get always this error
但我总是收到这个错误
java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access0(X11GraphicsEnvironment.java:62)
at sun.awt.X11GraphicsEnvironment.run(X11GraphicsEnvironment.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:112)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at java.awt.Toolkit.run(Toolkit.java:849)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:841)
at ij.io.Opener.openJpegOrGif(Opener.java:367)
at ij.io.Opener.openImage(Opener.java:220)
at ij.io.Opener.openImage(Opener.java:249)
at ij.io.Opener.open(Opener.java:116)
at ij.IJ.open(IJ.java:1112)
at ij.macro.Functions.open(Functions.java:2006)
at ij.macro.Functions.doFunction(Functions.java:129)
at ij.macro.Interpreter.doStatement(Interpreter.java:205)
at ij.macro.Interpreter.doBlock(Interpreter.java:515)
at ij.macro.Interpreter.runUserFunction(Interpreter.java:278)
at ij.macro.Interpreter.getFactor(Interpreter.java:1200)
at ij.macro.Interpreter.getTerm(Interpreter.java:1162)
at ij.macro.Interpreter.getExpression(Interpreter.java:1145)
at ij.macro.Interpreter.getBooleanExpression(Interpreter.java:881)
at ij.macro.Interpreter.getLogicalExpression(Interpreter.java:857)
at ij.macro.Interpreter.getBoolean(Interpreter.java:850)
at ij.macro.Interpreter.doIf(Interpreter.java:829)
at ij.macro.Interpreter.doStatement(Interpreter.java:217)
at ij.macro.Interpreter.doBlock(Interpreter.java:515)
at ij.macro.Interpreter.doStatement(Interpreter.java:241)
at ij.macro.Interpreter.doIf(Interpreter.java:831)
at ij.macro.Interpreter.doStatement(Interpreter.java:217)
at ij.macro.Interpreter.doStatements(Interpreter.java:195)
at ij.macro.Interpreter.run(Interpreter.java:99)
at ij.macro.Interpreter.run(Interpreter.java:65)
at ij.macro.Interpreter.run(Interpreter.java:75)
at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:127)
at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:112)
at ij.IJ.runMacroFile(IJ.java:103)
at ij.ImageJ.main(ImageJ.java:517)
I have tried everything to solve this problem like :
我已经尝试了一切来解决这个问题,例如:
export DISPLAY=:10.0
export DISPLAY=localhost:10.0
I tried also the port 0.0 but i get always the same error
我也试过端口 0.0 但我总是得到同样的错误
after trying xhost
尝试 xhost 后
xhost +local:all
xhost: unable to open display ""
xhost: unable to open display ":10.0"
how can i fix this
i thought that the X Server is not runing so i tried startx
its says its runing at that port
我该如何解决这个问题我认为 X 服务器没有运行所以我尝试了startx
它说它在那个端口运行
my system is Ubuntu server edition 10.04
我的系统是 Ubuntu 服务器版本 10.04
采纳答案by Maryam Saeidi
This command helped me to solve the problem:
这个命令帮我解决了这个问题:
export DISPLAY=:0
回答by Michael-O
You need to specify the -Djava.awt.headless=true
parameter at startup time.
您需要-Djava.awt.headless=true
在启动时指定该参数。
回答by grepit
This will fix it:
这将修复它:
/usr/bin/java -Djava.awt.headless=true $Your_program
回答by bebbo
Remove the DISPLAY variable
删除 DISPLAY 变量
unset DISPLAY
This helps in most cases (e.g. starting application servers or other java based tools) and avoids to modify all that many command lines.
这在大多数情况下都有帮助(例如启动应用程序服务器或其他基于 Java 的工具)并避免修改所有那么多命令行。
It can also be comfortable to add it to the .bash_profile for a dedicated app-server/tools user.
也可以很方便地将它添加到 .bash_profile 以供专用的 app-server/tools 用户使用。
回答by janex
the only way i got it to work was running the script with a template. e.g. sudo ./glassfish-3.1.2.2-unix.sh -s template
我让它工作的唯一方法是使用模板运行脚本。例如 sudo ./glassfish-3.1.2.2-unix.sh -s 模板
This installs Glassfish in Silent Mode. http://docs.oracle.com/cd/E18930_01/html/821-2427/ghmva.html
这将在静默模式下安装 Glassfish。http://docs.oracle.com/cd/E18930_01/html/821-2427/ghmva.html
回答by David
I run into the same error with you when i run the jconsole command at remote. I want to modify a parameter at jconsole that run on a remote Linux host, i can login the host use the secureCRT, the terminal throw this error information. Fortunately, when use the Putty, it's ok. Weird....
当我在远程运行 jconsole 命令时,我遇到了同样的错误。我想修改运行在远程Linux主机上的jconsole的一个参数,我可以使用secureCRT登录主机,终端抛出这个错误信息。幸运的是,当使用Putty时,没关系。奇怪的....
回答by user2945593
If you see this error in Hudson, try to remove the .java directory from your home directory, it may work for you.
如果您在 Hudson 中看到此错误,请尝试从您的主目录中删除 .java 目录,它可能对您有用。
回答by Puneetsri
In case anybody trying to run the automated unit tests via maven-surefire-plugin on CI(jenkins,..), and getting the above mentioned error, be sure to update your surefire plugin configuration :
如果有人试图通过 CI(jenkins,..) 上的 maven-surefire-plugin 运行自动化单元测试,并收到上述错误,请务必更新您的 surefire 插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.awt.headless>true</java.awt.headless>
</systemPropertyVariables>
</configuration>
</plugin>
回答by user3132194
If you start application on a remote server while logged in by ssh then another way would be to start ssh with -x
parameter or add ForwardX11 no
in your /etc/ssh/ssh_config
. In this case ssh will not create environment variable DISPLAY.
如果您在通过 ssh 登录时在远程服务器上启动应用程序,则另一种方法是使用-x
参数启动 ssh或ForwardX11 no
在您的/etc/ssh/ssh_config
. 在这种情况下,ssh 不会创建环境变量 DISPLAY。
回答by Koti Reddy
Michael-O gave useful approach to solve the problem. Another way to solve this is by starting the server with Putty Console.
Michael-O 给出了解决问题的有用方法。解决此问题的另一种方法是使用 Putty Console 启动服务器。