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)?

5
  • 7
    Call the main() method? Commented May 24, 2013 at 5: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
    Commented May 24, 2013 at 5: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
    Commented May 24, 2013 at 6: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
    Commented May 24, 2013 at 6:53
  • I don't have the .class file at compile time, it's compiled during the execution.
    – Bastien
    Commented May 24, 2013 at 8:29

2 Answers 2

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.