java - Run Jar file with more than one argument -
i building optimization jpeg-encoder written in java. benchmark want extract orginal code , optimized code separated jars. each jar has take 2 arguments. first on file name , secound repeat of compression of jpeg.
public static void main(string[] args) { string filepath = args[0]; try { int times = integer.getinteger(args[1]); runbenchmark(filepath, times); } catch(ioexception | numberformatexception ioe) { system.out.println("your arguments wrong! use follow order!"); system.out.println("1. argument must filename of image."); system.out.println("2. argument must number repeat compression."); } }
this main, witch handle args. cant run arguments on intellj . if compile jar, cant pass arg2.
i passed 2 arguments via configuration in intellj , nullpointerexception. tried figure out if java can take 2 arguments. wrote simple main in vim , compiled ran 2 args , worked. repeated in new project in intellj. working. why?
you have check if parameter int or not. use integer.parseint() , try-catch block inform user if failure happen.
int times = 0; try { times = integer.parseint(args[1]); } catch (exception e) { system.out.println("failure parameter"); }
Comments
Post a Comment