简体   繁体   中英

What are the steps of running a Java Swing application on Linux (not Ubuntu or Debian)?

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?

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. AX 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.

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