Search code examples
javajavafxruntime-errorjvm-arguments

How create bash file to launch Java program with VM Arguments


I need to create a shell script file to run my Java program. This program contains VM Arguments hence my question.

For the moment here is what I tried:

#!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

But the application does not launch and here is the error message:

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

This message indicates that the VM Arguments were not taken into account when launching the application.

I also tried without the echo to see if it worked but nothing either.

How can I make it work properly?


Solution

  • All arguments before either -jar jarfile or main.class.name are args for the VM. All arguments that follow are args for the application.

    You are passing the VM args to your app. Move the $vmargs to the front.