Hello, could anyone help me with this. I have a java program and I want to be able to execute a JAR file from within that program. Using Runtime.exec I can easily execute .exe files, how can I do the same with my jar files. Thank you.
Putting the jar file in the classpath is not going to help if you don't have the jar file in advance. I assume you want to do this without restarting your program.
So use a URLClassLoader to reference the jar file. Find out the main class from the Manifest. This will tell you the entry point. Use the URLClassLoader to load the main class, then invoke its main method with some arguments.
You will want to add exception handling to this example.