0

Is there any way to run a Java program from inside another Java program without using Runtime exec?

Is there some kind of JavaExecutor tool which one could use with a DiagnosticCollector? (Like JavaCompiler)?

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
Bastien
  • 658
  • 1
  • 9
  • 24
  • 7
    Call the `main()` method? – Moritz Petersen May 24 '13 at 05:49
  • What's the problem with using `Runtime.exec()`? Is the sub-program already compiled or do you only have the source? Do you want to run it in the same JVM or a child JVM? – Matt Ball May 24 '13 at 05:49
  • Sub-program is already compiled. So I can't call main()... There is no problem with runtime.exec but I must analyse any eventual exec error and so a tool using some kind of diagnostic collector would be nice. I don't care which JVM it uses as long as I can acces stderr. – Bastien May 24 '13 at 06:13
  • It does not matter if it is compiled. Make sure you have the .class files (or .jar file) in your classpath (both at compile time and runtime of your program) and it should be possible to access and call the main method. – devconsole May 24 '13 at 06:53
  • I don't have the .class file at compile time, it's compiled during the execution. – Bastien May 24 '13 at 08:29

2 Answers2

1

Call it through Reflection if you want to pass in class name during runtime. If program throws an exception, capture the stack trace and use it for further diagnostics.

RickDavis
  • 2,276
  • 6
  • 25
  • 31
0

Yes,IBM provides one Diagnostics Collector for gathering documentation and diagnostic data associated with Java Virtual Machine (JVM) problems. At JVM start up it runs a Diagnostic Configuration Check.

Manish Doshi
  • 1,205
  • 1
  • 9
  • 17