如何创建 bash 文件以使用 VM 参数启动 Java 程序

How create bash file to launch Java program with VM Arguments

我需要为 运行 我的 Java 程序创建一个 shell 脚本文件。该程序包含 VM 参数,因此是我的问题。

目前这是我尝试过的:

#!bin/bash

# VM Arguments 
set vmargs1 = "--module-path $/home/User/Desktop/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml"

java -jar /home/User/Desktop/Test.jar echo $vmargs1

但是应用程序没有启动,这是错误消息:

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

此消息表示启动应用程序时未考虑 VM 参数。

我也试过不使用 echo 看看它是否有效,但也没有。

如何让它正常工作?

-jar jarfilemain.class.name 之前的所有参数都是 VM 的参数。后面的所有参数都是应用程序的参数。

您正在将 VM args 传递给您的应用程序。将 $vmargs 移到前面。