0

I am trying to create some simple programs that allow you to create and access accounts. I am using the JLabel and JTextField methods to do so.

How do I use one main class to launch another?

For example, if I could execute cmd commands through Java, then I would run the following command: java -jar fileTwo.jar

Makyen
  • 31,849
  • 12
  • 86
  • 121
Cardinal System
  • 2,749
  • 3
  • 21
  • 42

1 Answers1

1

If I understand your question properly, you want to launch another program from your program.

If possible, you should call the main function of the second program from the first.

Otherwise, try Runtime.exec() or ClassLoader. Note that I've never used ClassLoader, so I might be interpreting the docs wrong, but it seems to be something that might accomplish you're looking for. Googling tells me that it's probably excessive to use it for a program such as yours, though, so I'd stick with Runtime.exec().

Edit: Runtime.getRuntime().exec("cmd /c java -jar fileTwo.jar"), assuming your jar is named fileTwo. Make sure your jar is executable.

Sarvadi
  • 550
  • 3
  • 13