Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

classLoader

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
Hallo,

I am trying to load dinamically a .class file, but I don't understand where I do have to place my file in order to be loaded. By using th simple code here below I keep on getting a not found exception. The myClass name should contain also the namespace of myClass? should it be something like "xy.myorg.myClass" ? I tried also that by the class was not found. Where exactly the classloader is looking for it?

thanks

Code:
public class MainClass 
{
    public static void main(String[] args)
    {
        ClassLoader classLoader = MainClass.class.getClassLoader();
        try 
        {
            Class aClass = classLoader.loadClass("myClass");
            System.out.println("aClass.getName() = " + aClass.getName());
        }
        catch (ClassNotFoundException e) 
        {
            e.printStackTrace();
        }
    }
}
 
I could be wrong about this but...

The class would need to be somewhere in your classpath. For windows XP, you can check your classpath by typing "set" at a command prompt. The CLASSPATH variable should tell you the locations.

-----------------------------------------
I cannot be bought. Find leasing information at
 
I added to my variable classpath the location of the .class file, but invane: it is not found.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top