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.

1 Answer 1

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"); 
Sign up to request clarification or add additional context in comments.

4 Comments

do you know where the default path to terminal is. Or where to find it
I don't think it will open terminal window. You can only execute some command.
I have tried and it worked on Ubuntu 14.04 + JDK 1.8
@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. stackoverflow.com/questions/5738259/… you can accept the answer if it was helpful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.