If the goal is to pass parameters to the jar, it is enough to treat the array of Strings that the main
method of the main class receives, because it is through it that external commands execute the execution of the jar in the virtual machine. >
To illustrate, I did the following example:
import javax.swing.JOptionPane;
public class MainTeste {
public static void main(String[] args) {
String commands = "";
for(String str : args) {
commands += str;
}
JOptionPane.showMessageDialog(null, "Foram passados os seguintes comandos: " + commands);
}
}
See that I'm scanning the array received by main and concatenating a variable in the part, and then displaying it. After generating a. jar
, just pass the parameters through a command line similar to below:
java -jar seuJarFile.jar comando1 comando2 comando3
See the code above, after generating the jar, working:
Notethattheparametersmustbeseparatedbyspace,ifyouhaveanyparametersthatcontainspace(suchasfilenamesorpaths,forexample),mustbeenclosedindoublequotationmarks.
Relatedtopics: