【问题标题】:How to make an installer for linux with jar file?如何使用 jar 文件为 linux 制作安装程序?
【发布时间】:2020-07-02 04:29:23
【问题描述】:

问题

  1. 如果 linux os 上没有安装 java jdk,jar 将不会运行。

  2. 如果在 linux 中运行 javafx jar 会出现这样的错误

    Error: Could not find or load main class application.Main Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

Afer,我做到了。成功了。

要使用终端运行 java-fx 应用程序,请按以下步骤操作:

安装openjfx(如果尚未安装):
sudo apt install openjfx

列出 javafx 库位置:
dpkg-query -L openjfx
输出应该是这样的:

。 /usr /usr/共享 /usr/share/doc /usr/share/doc/openjfx /usr/share/doc/openjfx/TODO.Debian /usr/share/doc/openjfx/changelog.Debian.gz /usr/share/doc/openjfx/版权 /usr/share/openjfx /usr/share/openjfx/lib /usr/share/openjfx/lib/javafx.properties /usr/share/openjfx/lib/javafx.base.jar /usr/share/openjfx/lib/javafx.controls.jar /usr/share/openjfx/lib/javafx.fxml.jar /usr/share/openjfx/lib/javafx.graphics.jar /usr/share/openjfx/lib/javafx.media.jar /usr/share/openjfx/lib/javafx.swing.jar /usr/share/openjfx/lib/javafx.web.jar

运行 jar 应用程序通过包含 javafx 路径和模块
java --module-path $PATH_TO_OPENJFX-LIB --add-modules module_1,module_2,module_3,...,module_n -jar $PATH_TO_JAR_FILE

示例:

java --module-path /usr/share/openjfx/lib --add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.media,javafx.web,javafx.swing -jar '/home/lotfi/Documents/MyAppfolder/my_application.jar'
  1. 如果某些时候 java 的版本与 jar 不同。罐子不起作用。

我想为没有上述问题的 java 制作安装程序。

即使用户没有在 Linux 操作系统上安装 java jdk,它也应该可以工作。

除此之外,我想在 linux os 的搜索选项中添加应用程序。

如何制作这样的应用程序?

求救!!!

【问题讨论】:

  • .deb packages 可以包含需求列表,这意味着您应该能够使 dpkg install jre + javafx 并使用其安装后脚本创建脚本文件以使用正确的参数启动应用程序。 (虽然不能写一个完整的答案,因为我目前只从 cmake C(++) 项目创建包)
  • @fabian 你能提供更多信息吗?
  • 你考虑过吗,github.com/openjfx/javafx-maven-plugin你可以用launcher脚本做一个jlink版本。
  • @matt 你的答案用于 javafx。回答问题 1 和 3。
  • 如果您在 Unbuntu 上安装软件时遇到问题,您应该考虑在 askubuntu.com 上提问

标签: java linux javafx


【解决方案1】:

您可以在 jar 的开头嵌入一个 shell 脚本,将 1)、2) 和 3) 中的所有逻辑放入其中,然后启动 jvm。

#!/bin/sh
....
java -jar "$0"
exit
%zip content begins here%

并以$ ./your.jar开头

您可以为此使用makeself-maven-plugin

spring-boot-maven-plugin 也有这个功能,embeddedLaunchScript https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html

【讨论】:

  • 你能提供更多关于问题 1,2 和 3 的信息吗?
【解决方案2】:

java 有几个工具可以实现这一点。 jlink 允许您将 jre 与您的 java 文件打包在一起。有一个maven plugin 专门用于完成这项任务。

如果您已经有一个工作的 maven/javafx 设置,那么您需要做的就是将插件添加到您的 pom.xml

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
       <version>0.0.4</version>
       <configuration>
       <mainClass>modulename/com.example.Main</mainClass>
       <launcher>nametolaunch</launcher>
    </configuration>
</plugin>

然后当你构建你的项目时。

mvn javafx:jlink

它将编译您的项目,并创建 jlink。在target 文件夹中,您将拥有一个文件夹image,其中包含您需要的所有内容。您可以将其压缩并在任何兼容平台上使用。

运行应用程序image/bin/nametolaunch

【讨论】:

  • 能给个分步教程吗?
猜你喜欢
  • 2011-08-04
  • 1970-01-01
  • 2014-07-29
  • 1970-01-01
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多