If the goal is to pass parameters to the jar, just treat the Strings array that method main
of the main class receives, because it is through it that external commands are passed the execution of the jar in the virtual machine.
To illustrate, I have elaborated 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);
}
}
Note that I am scanning the array received by the main and concatenating a variable to the part, and then displaying. 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:
It is worth noting that the parameters should be separated by space, if you have some parameter that contains space (such as file names or paths, for example), it should be passed between double quotes.
Related Topics:
It helped a lot, I made it work. Thanks.
– Ernani Jr