0

I am working on a project that requires an executable jar file but I still want the command line to show once it has been run. Is there a way to do this, or similar such as creating a new terminal window and execute the jar on that window.

I am fine with writing code for multiple operating systems. Thanks for the help.

Noah Cover
  • 23
  • 6

1 Answers1

0

Since the terminal path for each OS is different, you should write the code for each OS. You can try following Java code.

Runtime.getRuntime().exec("/path/to/terminal");

For example, if it is Ubuntu, the code should be,

Runtime.getRuntime().exec("/usr/bin/gnome-terminal");

Further if you want to check the system OS and architecture, you can get them from System properties.

System.getProperty("os.name");
System.getProperty("os.version");
System.getProperty("os.arch");
Chathura Buddhika
  • 2,067
  • 1
  • 21
  • 35
  • do you know where the default path to terminal is. Or where to find it – Noah Cover Jul 12 '17 at 03:41
  • I don't think it will open terminal window. You can only execute some command. – fg78nc Jul 12 '17 at 03:50
  • I have tried and it worked on Ubuntu 14.04 + JDK 1.8 – Chathura Buddhika Jul 12 '17 at 03:53
  • @NoahCover If it is Linux, the path should be `/usr/bin/gnome-terminal`. For windows, it should be in the system32 folder. But I have never used the Mac OS. For that, check this answer. https://stackoverflow.com/questions/5738259/open-a-new-prompt-terminal-window-from-java you can accept the answer if it was helpful. – Chathura Buddhika Jul 12 '17 at 04:08