1

I'm trying to create a java application which starts a new terminal without using java -jar. I tried using several methods, but none of them have worked.

I need this to work on osx, I was able to make it on windwos

7
  • 1
    What you have tried?
    – Vipin CP
    Commented Aug 1, 2016 at 12:15
  • What did you do on Windows? By the way, something was probably doing java -jar under the hood on Windows. Commented Aug 1, 2016 at 12:16
  • I tried Runtime.getRuntime().exec("open -a Terminal java -jar myjar.jar gui" and on start I'm checking if gui is in the start arguments
    – letsgo00
    Commented Aug 1, 2016 at 12:17
  • On windows i used the method explaimed above but instead of "open -a Terminal" I used "start -c"
    – letsgo00
    Commented Aug 1, 2016 at 12:19
  • why without using java -jar ? Commented Aug 1, 2016 at 12:29

1 Answer 1

1

You have to call your shell as a program

 Runtime runtime = Runtime.getRuntime();
 String[] args = { "/bin/sh", "-c", " java -jar myjar.jar" };
 final Process process = runtime.exec(args);

To respond to your specific request, this is my answer

1/ Create a shell script

For example call it loadJava.sh:

#!/bin/sh
java -jar path/to/jar/file.jar

2/ Call the shell script with this java code that open a terminal and run the shell script

Correct code for OSX is

Runtime.getRuntime().exec("/usr/bin/open -a Terminal /path/to/the/script");
4
  • /bin/sh/ is not a directory on osx
    – letsgo00
    Commented Aug 1, 2016 at 12:29
  • please remove end slash Commented Aug 1, 2016 at 12:31
  • But it does not create a new terminal window where i can see the output
    – letsgo00
    Commented Aug 1, 2016 at 12:33
  • But this still does not start my application in a new window. I want that if you double click the application it starts in a terminal
    – letsgo00
    Commented Aug 1, 2016 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.