ssh后如何在Mac OS X上运行Java GUI [英] How to run a java GUI on mac osx after ssh

查看:188
本文介绍了ssh后如何在Mac OS X上运行Java GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X 10.7.5上使用Java 1.7.0_67.这是我的世界GUI:

I am using java 1.7.0_67 on mac osx 10.7.5. Here is my hello world gui:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

public class helloWorld extends JFrame {
    helloWorld(String title) { 
        this.setSize(500,500); 
        setTitle(title); 
    }

    public static void main(String[] args) {
       helloWorld window = new helloWorld("Helloworld");
       window.setVisible(true);
       window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    }
}

当我打开Mac终端并键入java helloWorld时,这运行得很好.但是,当我从另一台主机ssh进入mac时,设置我的DISPLAY env变量并运行,我得到以下异常:

This runs just fine when i open a mac terminal and type java helloWorld. However, when I ssh into my mac from another host, set my DISPLAY env variable, and run, I get the following exception:

Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.GraphicsEnvironment.checkedHeadless(GraphicsEnvironment.java:207)
    at java.awt.Window.<init>(Window.java:535)
    at java.awt.Frame.<init>(Frame.java:420)
    at java.awt.Frame.<init>(Frame.java:385)
    at javax.swing.JFrame.<init>(JFrame.java:180)
    at helloWorld.<init>(helloWorld.java:8)
    at helloWorld.main(helloWorld.java:14)

这曾经在Java 1.6上运行,根据我的研究,这似乎是有目的的突破.

This used to work on Java 1.6, from what I've been able to research this appears to be a purposeful break.

有什么想法可以让我从远程主机上推入后显示gui?我不想使用X11(宁愿使用本机gui渲染).

Any ideas how I can get my gui to display after ssh-ing in from a remote host? I don't want to use X11 (would prefer native gui rendering).

推荐答案

Java开发人员

The Java developers chose to use the headless Toolkit when running in an ssh session on Mac OS X. You can convince Java to go ahead and display the GUI anyway by setting the AWT_TOOLKIT environment variable to CToolkit. For example, in bash:

export AWT_TOOLKIT=CToolkit
java helloWorld

设置了变量后,您的GUI应该会按预期显示.

With the variable set, your GUI should display as you expect.

这篇关于ssh后如何在Mac OS X上运行Java GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆