skip to Main Content

I have written a simple Java Swing application (It shows one image.jpg and a 2 buttons in the JFrame). I have a Linux system that I want this Java Swing application to run on start.

I connected to my Linux device with SSH using Putty. I checked and Java is not installed.
I will install Java using RPM but when I typed uname -m it prompted armv7l. I checked and it is a 32 bit device. But also it is an ARM. Which RPM version of Java should I use?

I have searched and found that there is a way that creates Linux service from Java application. But that doesn’t show any GUI.

I found that X and $DISPLAY have to be used to show GUI on Linux.

But I don’t know what steps I should follow.

Could you point me to the right direction?

Edit: My linux system has a screen connected to it but not a keyboard. I installed Java for a 32-bit ARM by transferring Java JDK with SSH and pscp. I can now execute Java Console Applications. I checked and there is X.org server on my Linux system. When I typed ps -A, I saw that Xorg is running. Should I kill the current Xorg? How can I make the X server show my Java Swing GUI?

2

Answers


  1. Here you can find arm version of Java : https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
    This Java 8 JDK, but you can also download the JRE.

    You can install from the .rpm or just uncompress the tar.gz archive.

    Concerning the graphical interface, you must install a X server, x.org is the most common one.
    Be aware that an X server is just a server that runs over a terminal on a screen, but it doesn’t do so much alone. You will not have a window with a taskbar and all.
    But if I understand your requirements, it looks like it’s what you are looking for. If you need more, you may want to install a window manager like XFCE.

    As soon as you have installed x.org you should be able to run any graphical application. A X client needs the DISPLAY environment variable to know the server, by default it’s :0, which is actually a short for 127.0.0.1:0.
    A quick check is to install xterm and try to run it.

    Because x.org run over a terminal (you will have to run startx command), you will just get a black screen when it will work the first time (except if you added a default app or a window manager). To be able to run an application by hand, you have to switch terminal.
    On linux you can have multiple terminal, to switch between them you can do ctrl-alt-F* (the function keys on top of the keyboard, I hope you don’t have a mac keyboard). On many system, the first terminal is on F1, but sometimes the x server is run on F3.
    Then a DISPLAY=:0 xterm must show a terminal on inside the x server.
    You can also run the application from ssh, the point is to precise the display using the env var.

    To install the X server, I suggest you to look the specific tutorial for your hardware (raspberry, beaglebone..). If you have an exotic hardware, try to follow any tutorial, but most of the time a simple apt install xorg is enough, but it’s driver-less.

    Good luck.

    Edit:
    I forgot. If you don’t have a screen connected on your device, installing an X server onto the linux board is useless, you can run an X server on your computer and run X application through SSH ssh -X toto@ip.
    But I guess you have a connected screen on your linux board.

    Edit 2:
    If you don’t have a keyboard connected but you have a running x.org, you must be able to run xcalc, xterm ect from SSH by setting DISPLAY=:0 env var.

    Login or Signup to reply.
  2. To run a GUI application inside a Linux-based machine, the $DISPLAY should be defined to pass all GUI info.

    So we have multiple ways to do that:

    1- Connect a real Display:
    So you will find the $DISPLAY environment variable defined, then you can run the GUI application.

    2- Use SSH with X forwarding:
    When you connect to a remote Linux system, ask it to forward the GUI operations buffer to your machine
    ssh -X run-my-gui-application.sh

    3- Fake the DISPLAY (Hardware solution):
    By injecting small real hardware like a USB connector (not a display) then the operating system will assume there is a display, then the GUI app will run

    4- Fake the DISPLAY (Software solution):
    By installing a package to emulate the DISPLAY, for example, use xvfb lib:

    sudo apt-get install xvfb
    
    # [GUI] headless mode
    # ~FAKE DISPLAY~ number 88
    nohup Xvfb :88 -ac & 
    export DISPLAY=:88.0
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search