0

I'm creating an operating system-like program in java and have run into a little trouble. I want the user to be able to run jar files of their choice in it, but I don't really know how though.

Basically, it will work like this:

  1. The user opens a program in the OS called "Import Jar".
  2. The user clicks "browse", then a JFileChooser pops up.
  3. After the user specified a file, they click "Finish".
  4. The Jar starts up in a JInternalFrame.
GreenJames
  • 21
  • 1
  • 8
  • Take a look here: [http://stackoverflow.com/questions/8496494/running-command-line-in-java](http://stackoverflow.com/questions/8496494/running-command-line-in-java) Kind regards – mrbela Apr 06 '16 at 14:35

1 Answers1

1

You can use the Runtime.exec(String) method for that.

For example:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("java -jar yourJar.jar");

Does start your jar within a running Java program. In your case you have to ensure that the jar yourJar.jar starts in a JInternalFrame.

mrbela
  • 4,477
  • 9
  • 44
  • 79
  • How would I start it in a the Internal Frame though? – GreenJames Apr 06 '16 at 14:42
  • You have to ensure, If you run the jar seperately on your own (by invoking "java -jar yourJar.jar" in -for example- Windows cmd) that it starts a for example JFrame. – mrbela Apr 06 '16 at 14:45