Swing heavy components in headless enviroment

A

Andres Medina

Hi

I developed a program that runs simulations. My first version used
JFrames to show a User Interface. But I noticed it would be very
helpful if the program could run in the background (I use Linux) and
perhaps I can run it remotely through ssh.

I changed everything so that, if the user choosed the "NO-GUI" option,
no JFrames were visible, altough I did not remove the instances of the
JFrames (Because to do so, I have to make big changes in the code).
The program works fine, for example in a GNOME terminal (of course,
the display is still there), but it does not run through ssh. I get
the following error:

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.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:310)
at java.awt.Frame.<init>(Frame.java:419)
at javax.swing.JFrame.<init>(JFrame.java:194)
at ams.utils.ui.SimUI.<init>(Unknown Source)
at ams.utils.ui.SimUI.main(Unknown Source)


Can anyone tell me, if it is posible to do what I am trying?
 
S

Steve W. Jackson

:Hi
:
:I developed a program that runs simulations. My first version used
:JFrames to show a User Interface. But I noticed it would be very
:helpful if the program could run in the background (I use Linux) and
:perhaps I can run it remotely through ssh.
:
:I changed everything so that, if the user choosed the "NO-GUI" option,
:no JFrames were visible, altough I did not remove the instances of the
:JFrames (Because to do so, I have to make big changes in the code).
:The program works fine, for example in a GNOME terminal (of course,
:the display is still there), but it does not run through ssh. I get
:the following error:
:
:Exception in thread "main" java.awt.HeadlessException:
:No X11 DISPLAY variable was set, but this program performed an
:eek:peration which requires it.
: at
: java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:15
: 9)
: at java.awt.Window.<init>(Window.java:310)
: at java.awt.Frame.<init>(Frame.java:419)
: at javax.swing.JFrame.<init>(JFrame.java:194)
: at ams.utils.ui.SimUI.<init>(Unknown Source)
: at ams.utils.ui.SimUI.main(Unknown Source)
:
:
:Can anyone tell me, if it is posible to do what I am trying?

If you revisit the API docs, you'll find that the mere act of
instantiating many Swing components throws the HeadlessException if
there's no graphics environment (see the JFrame constructors for an
example). So you've got to go back into the code and suppress the
instantiation of those items if you want to be able to run in this
environment.

Alternatively, as the message indicates, you may be able to set the
DISPLAY variable. But that may not be reliable -- can't say, as I
haven't tried this myself.

= Steve =
 
A

Ann

Andres Medina said:
Hi

I developed a program that runs simulations. My first version used
JFrames to show a User Interface. But I noticed it would be very
helpful if the program could run in the background (I use Linux) and
perhaps I can run it remotely through ssh.

I changed everything so that, if the user choosed the "NO-GUI" option,
no JFrames were visible, altough I did not remove the instances of the
JFrames (Because to do so, I have to make big changes in the code).
The program works fine, for example in a GNOME terminal (of course,
the display is still there), but it does not run through ssh. I get
the following error:

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.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:310)
at java.awt.Frame.<init>(Frame.java:419)
at javax.swing.JFrame.<init>(JFrame.java:194)
at ams.utils.ui.SimUI.<init>(Unknown Source)
at ams.utils.ui.SimUI.main(Unknown Source)


Can anyone tell me, if it is posible to do what I am trying?

I have not used X11 in a while, but the DISPLAY environment variable
is used to determine the location of the screen etc. for the server
which is normally your terminal but you can assign it to another
terminal if you want to. If you assign it to /dev/null it may not
work, but it is worth a try.
 
M

Mark Scott

On Thu, 11 Nov 2004 10:45:29 -0800, Andres Medina wrote:

[...]
I changed everything so that, if the user choosed the "NO-GUI" option,
no JFrames were visible, altough I did not remove the instances of the
JFrames (Because to do so, I have to make big changes in the code). The
program works fine, for example in a GNOME terminal (of course, the
display is still there), but it does not run through ssh. I get the
following error:

Exception in thread "main" java.awt.HeadlessException: No X11 DISPLAY
variable was set, but this program performed an operation which requires
it.
[...]

Can anyone tell me, if it is posible to do what I am trying?

If you're running ssh from an X session and your server's ssh daemon is
configured to permit X11 forwarding to the local display then pass the -X
flag to ssh (or put the corresponding option into your ssh config file).

E.g.

$ ssh -X user@server java -cp ...

The server config option you need is :

X11Forwarding yes

If it's not enabled then the admin might be prepared to enable it for you
(especially if you're the admin ;-) ), but do first read the ssh manpage
for a warning about using X11 forwarding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top