aspose file tools*
The moose likes Java in General and the fly likes class loader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "class loader " Watch "class loader " New topic
Author

class loader

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
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.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.
 
jQuery in Action, 2nd edition
 
subject: class loader