I am using a jar to run some code as a helper for a program (OSX). I want to open this jar programmatically, and have been using a ProcessBuilder to run it through the terminal.
However, I want to give the jar some arguments (specifically a file location, but that's irrelevant). I have using java -jar jarName arg
, but this doesn't work with people who don't have Java tools installed.
I have tried to use open jarName --args arg
, but the jar doesn't recognize the args.
As a test, I am just using the following code for now.
public static void main(String[] args) {
try {
// set a PrintStream to see the args presented
System.setOut(
new PrintStream(new FileOutputStream(new File(System.getProperty("user.home") + "/Desktop/argsTest.txt"))));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(argsSize: "+args.length");
for (String s : args)
System.out.println(s);
}
I am fine with trying other methods of opening jars, so long as they are available on all up to date systems.
I have the JRE packaged in the application, is there a way to use that?