I have a doubt on the classloader API FUNCTIONALITY. Say I have to classes classA and classB both with main methods. How can I call classB's main method from classA.Is it possible to perform it with class loader.May be I can call with classB.main().Or I may be able to execute it with Runtime class's exec method and pass the command as java ClassB.But can I do the same with some method in classLoader.
posted 10 years ago
There's nothing magic about the main() method of a class, once your program is running. You can call it just the same as any other method, providing the class is on the classpath.
If the class is not on the classpath, then you have to get hold of the class somehow, which might involve you using a ClassLoader directly.
The main() method's one magic feature is that the standard Java launcher calls main() as the entry point, after creating the JVM. However, you can write your own Java launcher, or use a third-party one; a custom launcher can call any method(s) it wants.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.