4
Contributors
6
Replies
26
Views
3 Years
Discussion Span
Last Post by JamesCherrill
0

Do you simply want to start the application in that jar executing, or do you want to use the classes inside that jar?

Edited by JamesCherrill

0

i simply want to use action listener to open a jar program within a certain directory

1

In that case you can use the ProcessBuilder class - it lets you start an external process, set its working directory etc.
See the usual API doc, or Google for tutorials

0

hmm, simplest way to launch a Java program from another Java program is to load the classes onto the active classpath, load the main class into a classloader, and then execute the main() method on that class.

No need to use ProcessBuilder to create a new JVM, just make sure you have the jar on your classpath and call SomeClass.main(new String[]) or something like that :)

0

SomeClass.main(null) or something like that...

Yes. That was the other solution I had in mind too, especially if he wants to interact with the classes in the jar directly.
ProcessBuilder would be more appropriate if the jar is just a "black box" application that happens to be in java, and especially if you want to pipe its sysin or sysout.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.