File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class loader

 
Renu Radhika
Ranch Hand
Posts: 243
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic