3

Ok, so basically, I wrote a java program that creates new java classes within the same folder as my current program. So far, that part works absolutely fine since it's just basically creating new text files. What I would like to know though, is if there is a way to run those created classes within the program without terminating 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'm using eclipse to do this.

2 Answers2

4

What I would actually try to do in that case without using external APIs, is to run cmd commands from Java.

In that case you can compile the created Java files and then run the .jar file for example, using terminal commands once more..

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

Community
  • 1
  • 1
Jack
  • 115
  • 1
  • 15
1

I am not completelly sure how much this will help in your case since it kinda relies a lot on what are you actually trying to achieve and how. But another option available to you is to call the main method of another class.
For example if you want to pass no arguements you can make a call like class2.main(new String[0]);

gkrls
  • 2,618
  • 2
  • 15
  • 29