Is there a way to run a java program from another Java program?

Ok, so basically I wrote a java program that creates new Java classes in the same folder as my current program. So far this part works absolutely fine as it just creates new text files. However, I would like to know if there is a way to run these generated classes inside a program without interrupting the running program that created them. So, basically, I want to write a program that creates, edits, and runs Java programs. Is there any method, function, API that helps to do something like this?

Also, I am using eclipse for this.


source to share

2 answers

I'm not entirely sure how much this will help in your case, as it sounds like what you are actually trying to achieve and how to do it. But another option available to you is to call a method of main

another class.
For example, if you want to pass no arguments, you can make the call as class2.main(new String[0]);



What I'm actually trying to do in this case without using external APIs is to run cmd commands from Java.

In this case, you can compile the generated Java files and then run the .jar file, for example using terminal commands again.

For cmd commands via Java you can refer to this link: Run cmd commands via java



All Articles