Reputation: 11
Can I give parameters to a jar file when I'm opening it with a batch file?
The batch file:
@ECHO OFF
start java -jar 2D_TestGame.jar
DebugMode = true
And this debug mode = true
line giving a true
value for line DebugMode
in program
Upvotes: 0
Views: 212
Reputation: 61
This page describes how to pass parameters to a Java program's main-method using command line parameters: https://www.tutorialspoint.com/Java-command-line-arguments#:~:text=A%20command%2Dline%20argument%20is,array%20passed%20to%20main(%20).
As you can see, that is actually the reason why you always have the String[] args as a parameter of the main-method.
A working solution for you would be:
java -jar 2D_TestGame.jar true
And then the following in the main-method of your Java-program:
public static void main(String[] args) {
if (args.length > 0) {
// Convert the String ("true" or "false") to a boolean
DebugMode = Boolean.parseBoolean(args[0]);
}
(Assuming you have already described boolean DebugMode as a class-variable
Upvotes: 1