Sanyam Goel
Sanyam Goel

Reputation: 2180

Is it possible in Java to invoke main method in new process with reflection

Is it possible to execute a statement such as m.invoke(param1 ,param2) in a new Process.

i.e., I want to execute a Java class file by first iteratively searching for its main class using reflection and on finding the main class to invoke it in a new process.

Upvotes: 1

Views: 1318

Answers (1)

Puspendu Banerjee
Puspendu Banerjee

Reputation: 2651

Definitely.

  1. Find all available classes in Path
  2. Introspect and find the class which has main method[check signature]
  3. Use java ProcessBuilder[JRE 5 +] or create a new java.lang.Process to spawn the new process it should "just work"

Upvotes: 5

Related Questions