I wrote a Java program that when its executable .jar is opened manually, it re-opens itself inside the operating system's shell console. The purpose of this is to have a C#-style console application where the user can enter commands, without the user needing to manually open the shell console and run the java -jar ...
command to open the application.
Would you consider this a good implementation?
Would you make a custom console GUI instead of using the OS's console?
public static void main(String[] args){
if(args.length == 0){ // then re-open in console with argument to indicate that there's no need to re-open next time.
try {
String os = System.getProperty("os.name").toLowerCase();
String path = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsolutePath();
if(os.contains("mac")){
String command = "tell application \"Terminal\"\n" +
"do script \"java -jar \'" + path + "\' console\"\n" +
"activate\n" +
"end tell";
Runtime.getRuntime().exec( new String[]{"osascript", "-e", command} );
System.exit(0);
} else if(os.contains("win")) {
Runtime.getRuntime().exec("cmd /c start cmd.exe /K java -jar \"" + path + "\" console");
System.exit(0);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
System.out.println("Enter command. 'help' for list of commands.");
while(true)
nextCommand();
}
bin/run.bat
,bin/launch.exe
whatever. If he somehow invokesFoobar.main
inlib/foobar.jar
in some other way, maybe he knows what he is doing. Just ensure you have the parameters and let anything else slide. \$\endgroup\$ – abuzittin gillifirca Mar 25 '19 at 8:43