简体   繁体   English

在 Linux 上运行 Java Swing 应用程序的步骤是什么?

[英]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 ).我写了一个简单的 Java Swing 应用程序(它在JFrame中显示一个 image.jpg 和一个 2 个按钮)。 I have a Linux system that I want this Java Swing application to run on start.我有一个 Linux 系统,我希望这个 Java Swing 应用程序在启动时运行。

I connected to my Linux device with SSH using Putty.我使用 Putty 使用 SSH 连接到我的 Linux 设备。 I checked and Java is not installed.我检查并没有安装 Java。 I will install Java using RPM but when I typed uname -m it prompted armv7l .我将使用 RPM 安装 Java 但是当我输入uname -m它提示armv7l I checked and it is a 32 bit device.我查了一下,它是一个 32 位的设备。 But also it is an ARM.但它也是一个 ARM。 Which RPM version of Java should I use?我应该使用哪个 RPM 版本的 Java?

I have searched and found that there is a way that creates Linux service from Java application.我搜索并发现有一种方法可以从 Java 应用程序创建 Linux 服务。 But that doesn't show any GUI.但这并没有显示任何 GUI。

I found that X and $DISPLAY have to be used to show GUI on Linux.我发现必须使用 X 和 $DISPLAY 在 Linux 上显示 GUI。

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.编辑:我的 linux 系统连接了一个屏幕,但没有连接键盘。 I installed Java for a 32-bit ARM by transferring Java JDK with SSH and pscp . I installed Java for a 32-bit ARM by transferring Java JDK with SSH and pscp . I can now execute Java Console Applications.我现在可以执行 Java 控制台应用程序。 I checked and there is X.org server on my Linux system.我查了一下,我的 Linux 系统上有 X.org 服务器。 When I typed ps -A , I saw that Xorg is running.当我输入ps -A时,我看到 Xorg 正在运行。 Should I kill the current Xorg?我应该杀死当前的 Xorg 吗? How can I make the X server show my Java Swing GUI?如何让 X 服务器显示我的 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. 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.您可以从 .rpm 安装或仅解压缩 tar.gz 存档。

Concerning the graphical interface, you must install a X server, x.org is the most common one.关于图形界面,你必须安装一个 X 服务器,x.org 是最常见的。 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.请注意,X 服务器只是在屏幕上的终端上运行的服务器,但它并不能单独做很多事情。 You will not have a window with a taskbar and all.您将不会拥有带有任务栏和所有功能的 window。 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.如果您需要更多,您可能需要安装像 XFCE 这样的 window 管理器。

As soon as you have installed x.org you should be able to run any graphical application.一旦您安装了 x.org,您应该能够运行任何图形应用程序。 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 . AX 客户端需要 DISPLAY 环境变量来了解服务器,默认为:0 ,实际上是127.0.0.1:0的缩写。 A quick check is to install xterm and try to run it.快速检查是安装 xterm 并尝试运行它。

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).因为 x.org 在终端上运行(您必须运行startx命令),所以当它第一次运行时,您只会得到一个黑屏(除非您添加了默认应用程序或 window 管理器)。 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).在 linux 上,您可以有多个终端,要在它们之间切换,您可以执行ctrl-alt-F* (键盘顶部的 function 键,希望您没有 mac 键盘)。 On many system, the first terminal is on F1, but sometimes the x server is run on F3.在许多系统上,第一个终端在 F1 上,但有时 x 服务器在 F3 上运行。 Then a DISPLAY=:0 xterm must show a terminal on inside the x server.然后DISPLAY=:0 xterm必须在 x 服务器内部显示一个终端。 You can also run the application from ssh, the point is to precise the display using the env var.您还可以从 ssh 运行应用程序,重点是使用 env var 精确显示。

To install the X server, I suggest you to look the specific tutorial for your hardware (raspberry, beaglebone..).要安装 X 服务器,我建议您查看针对您的硬件(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.如果您有一个奇特的硬件,请尝试遵循任何教程,但大多数时候简单的apt install xorg就足够了,但它是无驱动程序的。

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 .如果你的设备上没有连接屏幕,在linux板子上安装X server是没用的,你可以在你的电脑上运行一个X server,通过SSH ssh -X toto@ip运行X应用程序。 But I guess you have a connected screen on your linux board.但我猜你的 linux 板上有一个连接的屏幕。

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.编辑 2:如果你没有连接键盘但你有一个正在运行的 x.org,你必须能够通过设置 DISPLAY=:0 env var 从 SSH 运行 xcalc、xterm 等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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