Elt*_*ooo 85 java linux x11 xserver
我有一个脚本使用java连接到localhost上的端口10.0中显示X11
但我总是得到这个错误
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.access$200(X11GraphicsEnvironment.java:62)
at sun.awt.X11GraphicsEnvironment$1.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$2.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)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切来解决这个问题,如:
export DISPLAY=:10.0
export DISPLAY=localhost:10.0
Run Code Online (Sandbox Code Playgroud)
我也尝试了端口0.0但我总是得到相同的错误
在尝试xhost之后
xhost +local:all
xhost: unable to open display ""
xhost: unable to open display ":10.0"
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题我认为X服务器没有运行所以我试过startx它说它在那个端口运行
我的系统是Ubuntu服务器版10.04
Mic*_*l-O 53
您需要-Djava.awt.headless=true在启动时指定参数.
beb*_*bbo 37
删除DISPLAY变量
unset DISPLAY
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下都有帮助(例如,启动应用程序服务器或其他基于Java的工具),并避免修改所有那么多命令行.
对于专用的app-server/tools用户,将它添加到.bash_profile也很舒服.
Mar*_*idi 33
这个命令帮助我解决了这个问题:
export DISPLAY=:0
Run Code Online (Sandbox Code Playgroud)
小智 9
如果有人试图通过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>
Run Code Online (Sandbox Code Playgroud)
这将解决它:
/usr/bin/java -Djava.awt.headless=true $Your_program
Run Code Online (Sandbox Code Playgroud)
对我来说,以-Y而不是 -X 的身份登录有效。
如果您的 X11 不受信任,如下所示,请尝试使用 -Y 标志(如果您信任主机):
警告:不受信任的 X11 转发设置失败:未生成 xauth 密钥数据
小智 6
如果您尝试使用 su 导出显示,但它仍然不起作用。这对我有用。尝试为 sudo 用户提供 X11 转发。
使用 ssh 的 -X 选项连接远程主机。
# ssh -X root@remote-host
Run Code Online (Sandbox Code Playgroud)
现在列出当前用户的 cookie 设置。
# xauth list $DISPLAY
node01.thegeekdiary.com/unix:10 MIT-MAGIC-COOKIE-1 dacbc5765ec54a1d7115a172147866aa
# echo $DSIPLAY
localhost:10.0
Run Code Online (Sandbox Code Playgroud)
使用 sudo 切换到另一个用户帐户。将上面命令输出中的 cookie 添加到 sudo 用户。
# sudo su - [user]
# xauth add node01.thegeekdiary.com/unix:10 MIT-MAGIC-COOKIE-1 dacbc5765ec54a1d7115a172147866aa
Run Code Online (Sandbox Code Playgroud)
为 sudo 用户再次导出步骤 2 中的显示。尝试使用 xclock 命令来验证 x 客户端应用程序是否按预期工作。
# export DISPLAY=localhost:10.0
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题
xhost +
Run Code Online (Sandbox Code Playgroud)
但请注意,这xhost +将完全停用身份验证并允许每个人访问屏幕上的所有应用程序。
xhost +si:localuser:root似乎与正确的身份验证类似。
| 归档时间: |
|
| 查看次数: |
245227 次 |
| 最近记录: |