wood burning stoves 2.0*
The moose likes Java in General and the fly likes Any way to make main class loaded by your classloader? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Any way to make main class loaded by your classloader?" Watch "Any way to make main class loaded by your classloader?" New topic
Author

Any way to make main class loaded by your classloader?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I know that in my code, I can use my own classloader (that i wrote) to load classes. Is there a way to make your main class loaded by this classloader? In other words, when i start up with: java blah
can i make blah loaded by my classloader: NClassLoader? Say with a -D call or something? Is there a way to do it for a jar file too?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
OK - so I am confused about the question.
When you invoke a program using
>java blah
the class IS automatically loaded by the bootstrap class loader and the main class invoked for you.
If you invoke a jar file, the manifest in investigated to identify the name of the class that contains the main method that you want invoked at startup. That means that the containing class is loaded first.
Is that your question?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Oh - I think that I get it. You want to use YOUR classloader.
In that case you probably need a driver class that gets loaded by the bootstrap classloader and have IT call your class with your classloader.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Any way to make main class loaded by your classloader?