有一个 jar 可执行文件(与外部库一起打包),我将如何在没有 Java/JRE 的服务器上实现它

Have a jar executable, (packaged with external libraries), how would I implement it on a server that doesn't have Java/JRE

有问题的服务器是 windows 服务器,我打算 运行 该程序在命令行上使用批处理文件。但是,服务器没有安装 Java,那么有没有办法将 JRE(或任何 Java 需要 运行 程序)打包到 jar 文件中?服务器上需要额外的 applications/programs 吗?

额外信息: 我使用 eclipse 打包了 jar 文件,有大约 3 个外部库,并且在我的计算机上运行良好(安装了 Java)。

谢谢!

您可以使用 JAR 分发 JRE,但不能将 JRE 打包到 jar 中。您还应该注意一个执行脚本,该脚本将设置适当的环境变量并在之后启动您的 jar。

以下是分发包的可能结构:

-- App folder
|
+-- JRE folder
|   |
|   +-- bin
|   |
|   +-- etc..
|-- your jar
|-- execution script (e.g. start.bat)

如果您使用的是 windows,我过去曾使用过 launch4j,效果非常好。它允许您将任意数量的 jar 和 dll(如果您使用本机代码)打包到一个可执行文件中。

来自他们的文档:

Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executables. The executable can be configured to search for a certain JRE version or use a bundled one, and it's possible to set runtime options, like the initial/max heap size. The wrapper also provides better user experience through an application icon, a native pre-JRE splash screen, and a Java download page in case the appropriate JRE cannot be found.