简体   繁体   中英

How can I run a Java GUI application on a headless Linux that does not support GUI?

I have created a Java GUI application that is running in Windows. Now I want it to run it on a headless Linux instance that does not support GUI. I wanted to convert the GUI to TUI. Is there a way I can substitute some classes and make it run in Linux by TUI. Please help.

You can use PeterMmm's suggestion http://www.pitman.co.za/projects/charva/index.html

Or, you can run the GUI on your local machine by running an X server, then connecting to the Linux box using ssh -X . That will show the GUI on your local machine, but the program is actually running on the linux box.

Or, you can run XVFB to fake a GUI on the Linux box. You won't be able to see the GUI or interact with it in any way, but that might not matter to you.

有一些Java的ncurses实现可用,例如: http : //www.pitman.co.za/projects/charva/index.html

If you are connecting from another X running Linux machine put following to your user ssh config ( ~/.ssh/config ):

Compression yes
CompressionLevel 9
ForwardX11 yes
ForwardX11Trusted yes

Then when you login to remote Linux machine your GUI going to be forwarded to local screen. Note that it could be slow... notably some AWT applications are really slow even on LAN.

If on Windows, intall CygWin and its Xserver components. Also OpenSSH can be helpful. When you going to connect through CygWin's ssh , use the same config as above. Of course run Xserver prior connecting to remote machine. You also can use Putty to connect to remote, but don't forget to enable X11 forwarding and compression in session config.

Remote machine must have xauth installed + sshd must have X11Forwarding enabled. If OK echo $DISPLAY will show localhost:10 .

For the sake of spreading a simple and effective solution, I copy the answer provided by @fossfreedom on SA "Ask Ubuntu":

sudo apt-get install xvfb

then:

xvfb :1 -screen 0 800x600x8 &
export DISPLAY=":1"
java application_name.jar

or

xvfb-run -a -e /tmp/some/log/file.log java -jar /home/user/somejava.jar

-> see: https://askubuntu.com/questions/50599/how-do-you-run-a-gui-application-without-gui-gui-application-as-daemon-on-headl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM