简体   繁体   English

如何在 Linux 中运行为 Windows 和 Mac 构建的 .jar 文件?

[英]How can I run a .jar file that was build for Windows and Mac in Linux?

I need to run a Java app ("Exactly") on Linux. It is a software to transfer data and used by an institution I have to cooperate with.我需要在Linux上运行一个Java应用程序(“Exactly”)。它是一个传输数据的软件,我必须与之合作的机构使用。 https://www.weareavp.com/products/exactly/ Codebase is here: https://github.com/WeAreAVP/uk-exactly https://www.weareavp.com/products/exactly/代码库在这里: https://github.com/WeAreAVP/uk-exactly

Unfortunately, the programs website offers only downloads for Mac and Windows, but essentially it is a Java Application.不幸的是,程序网站仅提供 Mac 和 Windows 的下载,但本质上它是一个 Java 应用程序。 Until now, I though, Java Applications run on every platform that supports a virtual Java machine.直到现在,Java 应用程序在支持虚拟 Java 机器的每个平台上运行。 For older versions of "Exactly" there were also a dedicated.jar download available.对于“Exactly”的旧版本,还有专门的 .jar 下载可用。 In the current "Exactly" User Guide ( https://www.weareavp.com/wp-content/uploads/2018/06/Exactly-User-Guide_v.0.1.5.pdf ) I found this sentence: "The Java jar file is now contained within either of the two Windows packages (32 or 64). You can run the Java jar file (located in the /dist path) once you unzip the Windows package."在当前的“确切”用户指南( https://www.weareavp.com/wp-content/uploads/2018/06/Exactly-User-Guide_v.0.1.5.pdf )中,我发现了这句话:“Java jar 文件是现在包含在两个 Windows 包(32 或 64)中的任何一个中。解压缩 Windows package 后,您可以运行 Java jar 文件(位于 /dist 路径中)。

I downloaded and unziped the Java files from the 64bit package to the directory: ~/java-anwendungen/exactly/我从 64 位 package 下载并解压了 Java 文件到目录: ~/java-anwendungen/exactly/

In ~/java-anwendungen/exactly/dist I found the exactly.jar file.~/java-anwendungen/exactly/dist中,我找到了exactly.jar文件。 I made it executable and tried to start it with no success.我使它可执行并尝试启动它但没有成功。

$ java -jar exactly.jar
Fehler: Zum Ausführen dieser Anwendung benötigte JavaFX-Runtime-Komponenten fehlen
(Error: to execute this app needed JavaFX-runtime-components missing)

I'm not a Java Developer, so I do not know how to proceed, to get the.jar file running on Ubuntu Linux. I tried some solutions I found in Inte.net (see below), but none worked out fine.我不是 Java 开发人员,所以我不知道如何继续,让 .jar 文件在 Ubuntu Linux 上运行。我尝试了在 Inte.net 中找到的一些解决方案(见下文),但没有一个解决方案很好。 Any help and advice are welcome!欢迎任何帮助和建议!

My Environment: ubuntu 18.04.6 LTS我的环境:ubuntu 18.04.6 LTS

$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)

The exactly directory:确切的目录:

(base) viejo@notebooka:~/java-anwendungen/exactly/dist$ ls -l
insgesamt 488
drwx------ 2 viejo viejo   4096 Nov 26 18:48 bundles
-rw-rw-r-- 1 viejo viejo    696 Nov 27 01:22 derby.log
-rwxrwxr-x 1 viejo viejo 236145 Sep 19  2017 exactly.jar
-rwxrwxr-x 1 viejo viejo 236352 Nov 26 19:27 exactly.run
-rwxrwxr-x 1 viejo viejo    198 Nov 26 19:14 launchExactly
drwx------ 2 viejo viejo   4096 Nov 26 18:48 lib
-rw-rw-r-- 1 viejo viejo      0 Nov 27 01:22 logfile.txt
-rw-rw-r-- 1 viejo viejo    207 Nov 26 19:24 stub.sh
drwxrwxr-x 5 viejo viejo   4096 Nov 27 01:22 ukexactly

note: The files exactly.run , launchExactly and stub.sh are created by me following the instructions in proposed solutions I found in Inte.net (see below) The files ukexactly , logfile.txt and derby.log were created by solution no.3.注意:文件exactly.runlaunchExactlystub.sh是我按照我在ukexactly中找到的建议解决方案中的logfile.txt derby.log的(见下文) 3.

The directory I found javafx (after installing it from Ubuntu repository):我找到的目录 javafx(从 Ubuntu 存储库安装后):

(base) viejo@notebooka:/usr/share/openjfx/lib$ ls -l
insgesamt 6500
lrwxrwxrwx 1 root root      26 Feb 19  2019 javafx.base.jar -> ../../java/javafx-base.jar
lrwxrwxrwx 1 root root      30 Feb 19  2019 javafx.controls.jar -> ../../java/javafx-controls.jar
lrwxrwxrwx 1 root root      26 Feb 19  2019 javafx.fxml.jar -> ../../java/javafx-fxml.jar
lrwxrwxrwx 1 root root      30 Feb 19  2019 javafx.graphics.jar -> ../../java/javafx-graphics.jar
lrwxrwxrwx 1 root root      27 Feb 19  2019 javafx.media.jar -> ../../java/javafx-media.jar
-rw-r--r-- 1 root root     113 Feb 19  2019 javafx.properties
lrwxrwxrwx 1 root root      27 Feb 19  2019 javafx.swing.jar -> ../../java/javafx-swing.jar
lrwxrwxrwx 1 root root      25 Feb 19  2019 javafx.web.jar -> ../../java/javafx-web.jar
-rw-r--r-- 1 root root 6651322 Feb 19  2019 src.zip

The directory the symlinks point to:符号链接指向的目录:

(base) viejo@notebooka:/usr/share/java$ ls -l
insgesamt 10900
-rw-r--r-- 1 root root    5232 Feb 21  2019 gettext.jar
-rw-r--r-- 1 root root   35257 Apr 25  2018 java-atk-wrapper.jar
-rw-r--r-- 1 root root    2989 Sep 20  2018 java_defaults.mk
-rw-r--r-- 1 root root  749850 Feb 19  2019 javafx-base-11.jar
lrwxrwxrwx 1 root root      18 Feb 19  2019 javafx-base.jar -> javafx-base-11.jar
-rw-r--r-- 1 root root 2510966 Feb 19  2019 javafx-controls-11.jar
lrwxrwxrwx 1 root root      22 Feb 19  2019 javafx-controls.jar -> javafx-controls-11.jar
-rw-r--r-- 1 root root  127377 Feb 19  2019 javafx-fxml-11.jar
lrwxrwxrwx 1 root root      18 Feb 19  2019 javafx-fxml.jar -> javafx-fxml-11.jar
-rw-r--r-- 1 root root 4365220 Feb 19  2019 javafx-graphics-11.jar
lrwxrwxrwx 1 root root      22 Feb 19  2019 javafx-graphics.jar -> javafx-graphics-11.jar
-rw-r--r-- 1 root root  270551 Feb 19  2019 javafx-media-11.jar
lrwxrwxrwx 1 root root      19 Feb 19  2019 javafx-media.jar -> javafx-media-11.jar
-rw-r--r-- 1 root root  119827 Feb 19  2019 javafx-swing-11.jar
lrwxrwxrwx 1 root root      19 Feb 19  2019 javafx-swing.jar -> javafx-swing-11.jar
-rw-r--r-- 1 root root  714674 Feb 19  2019 javafx-web-11.jar
lrwxrwxrwx 1 root root      17 Feb 19  2019 javafx-web.jar -> javafx-web-11.jar
-rw-r--r-- 1 root root    5385 Nov 18 14:52 java_uno.jar
-rw-r--r-- 1 root root     368 Nov 18 14:52 juh-7.2.3.jar
lrwxrwxrwx 1 root root      13 Nov 18 14:52 juh.jar -> juh-7.2.3.jar
-rw-r--r-- 1 root root     356 Nov 18 14:52 jurt-7.2.3.jar
lrwxrwxrwx 1 root root      14 Nov 18 14:52 jurt.jar -> jurt-7.2.3.jar
-rw-r--r-- 1 root root    2613 Feb 21  2019 libintl.jar
-rw-r--r-- 1 root root 2191511 Nov 18 14:52 libreoffice-7.2.3.jar
lrwxrwxrwx 1 root root      21 Nov 18 14:52 libreoffice.jar -> libreoffice-7.2.3.jar
-rw-r--r-- 1 root root     356 Nov 18 14:52 ridl-7.2.3.jar
lrwxrwxrwx 1 root root      14 Nov 18 14:52 ridl.jar -> ridl-7.2.3.jar
-rw-r--r-- 1 root root     356 Nov 18 14:52 unoil-7.2.3.jar
lrwxrwxrwx 1 root root      15 Nov 18 14:52 unoil.jar -> unoil-7.2.3.jar
-rw-r--r-- 1 root root    4727 Nov 18 14:52 unoloader-7.2.3.jar
lrwxrwxrwx 1 root root      19 Nov 18 14:52 unoloader.jar -> unoloader-7.2.3.jar

My inte.net research lead to various proposed solutions, but none worked out:我的 inte.net 研究导致了各种提议的解决方案,但都没有成功:

Solution 1 create a bash script:解决方案 1 创建一个 bash 脚本:

https://edencoding.com/runtime-components-error/#jar https://edencoding.com/runtime-components-error/#jar

see also: Convert.jar to an application for Windows, Linux & Mac另请参阅: 将 jar 转换为适用于 Windows、Linux 和 Mac 的应用程序

My bash file: launchExactly :我的 bash 文件: launchExactly

#!/bin/bash

java -jar exactly.jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls,javafx.fxml
$ ./launchExactly
Fehler: Zum Ausführen dieser Anwendung benötigte JavaFX-Runtime-Komponenten fehlen

Solution 2 append jar to a bash script:解决方案2 append jar 到bash脚本:

https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable

Create a bash file:创建一个 bash 文件:

    #!/bin/sh
    MYSELF=`which "$0" 2>/dev/null`
    [ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
    java=java
    if test -n "$JAVA_HOME"; then
        java="$JAVA_HOME/bin/java"
    fi
    exec "$java" $java_args -jar $MYSELF "$@"
    exit 1 

Append the.jar File: Append.jar文件:

cat stub.sh exaxtly.jar > exactly.run && chmod +x exactly.run

Also fails to start the jar:也无法启动 jar:

$ exactly.run
exactly.run: Befehl nicht gefunden. (command not found)

$ ./exactly.run
Fehler: Zum Ausführen dieser Anwendung benötigte JavaFX-Runtime-Komponenten fehlen
(error: JavaFX-runtime-components needed to execute app missing)

Solution 3 start.jar with parameters on comandline:解决方案 3 start.jar 在命令行上带有参数:

How do I fix JavaFX runtime components are missing? 如何修复 JavaFX 运行时组件丢失?

$ java --module-path /usr/share/openjfx/lib --add-modules ALL-MODULE-PATH -jar exactly.jar

Result:结果:

$  java --module-path /usr/share/openjfx/lib --add-modules ALL-MODULE-PATH -jar exactly.jar
[EL Info]: 2021-11-27 01:22:39.859--ServerSession(255728718)--EclipseLink, version: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
[EL Info]: connection: 2021-11-27 01:22:40.605--ServerSession(255728718)--file:/home/viejo/java-anwendungen/exactly/dist/exactly.jar_UKSipperflyPU login successful
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at uk.sipperfly.ui.Exactly.<init>(Exactly.java:107)
    at uk.sipperfly.ui.Exactly$83.run(Exactly.java:2971)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

The created derby.log file contains this information:创建的 derby.log 文件包含以下信息:

----------------------------------------------------------------
Mon Nov 29 12:59:52 CET 2021:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.11.1.1 - (1616546): instance a816c00e-017d-$
on database directory /home/viejo/java-anwendungen/exactly/dist/ukexactly with class loader java.net.URLClassLoader@$
Loaded from file:/home/viejo/java-anwendungen/exactly/dist/lib/derby.jar
java.vendor=Ubuntu
java.runtime.version=11.0.11+9-Ubuntu-0ubuntu2.18.04
user.dir=/home/viejo/java-anwendungen/exactly/dist
os.name=Linux
os.arch=amd64
os.version=5.4.0-90-generic
derby.system.home=null
Database Class Loader started - derby.database.classpath=''

The created logfile.txt is empty.创建的 logfile.txt 为空。

This attempt was the most promising, since at least the.jar started but it ended quickly in the above error message.这种尝试是最有希望的,因为至少 .jar 开始了,但很快就在上面的错误消息中结束了。

Note: A combination of solution 1 and 3 by changing the bash-script of solution 1 with the parameters from solution 3 resulted in the same errors of solution 3.注意:通过使用解决方案 3 中的参数更改解决方案 1 的 bash 脚本来组合解决方案 1 和 3 会导致与解决方案 3 相同的错误。

Now I am stuck and do not now how to proceed or if it is of any value to try to get the.jar file run under Linux.现在我被卡住了,现在不知道如何继续,或者尝试让 .jar 文件在 Linux 下运行是否有任何价值。

Your error seems to be related to Another issue & not with the Java dependencies.您的错误似乎与另一个问题有关,而不是与 Java 依赖项有关。 Kindly check any image file is missing while migrating the project or creating the jar file.请在迁移项目或创建 jar 文件时检查是否缺少任何图像文件。

If possible could you please paste the code or screenshot of the code you are trying to run?如果可能的话,您能否粘贴您尝试运行的代码的代码或屏幕截图?

You need an Instance of Java 8. The Newer verions don't have JavaFX libaries anymore.您需要一个 Java 8 的实例。较新的版本不再具有 JavaFX 库。

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

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