aspose file tools*
The moose likes Other Java Products and Servers and the fly likes Cannot instantiate class: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Cannot instantiate class: " Watch "Cannot instantiate class: " New topic
Author

Cannot instantiate class:

sandesh bangera
Greenhorn

Joined: Nov 13, 2002
Posts: 12
hi,

this problem could be more to do with the web server than servlets itself.

WebServer: SunOne 6.0 SP8
Platform : Solaris 8

LDAP: Netscape directory server
Platform: Solaris 2.6

Got a problem with a servlet that interacts with a LDAP server. I use the following line to initlise Directory Context

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

however, the system throws the following exception at runtime

"Cannot instantiate class: com.sun.jndi.ldap.LdapCtxFactory"

com.sun.jndi.ldap.LdapCtxFactory is present in a jar called ldap.jar which i have specifed in my classpath. Also set the nobody as the file owner and its prviligies to 777

Using truss i can confirm that the webserver does resolve and get a filehandle to the ldap.jar file.

has anyone come across a similar problem where the class could not be initiated despite being present in the classpath.

Appricate if you could provide some answers.

Mods: In case this topic has been answered before, could you point me to the right forum please.

Thanks & Regards
Sandesh
[ January 13, 2006: Message edited by: sandesh bangera ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Applications running inside servlet containers don't use the classpath, ignoring it allows a single container to run multiple applications without their code bases interfering with each other.

I'll move this to the Sun One forum, but basically you should put ldap.jar in the lib directory for that domain.
sandesh bangera
Greenhorn

Joined: Nov 13, 2002
Posts: 12
Thanks David.

I will try this out first thing on Monday.
sandesh bangera
Greenhorn

Joined: Nov 13, 2002
Posts: 12
Fixed this. this is due to the different class loaders introduced in JDK 2 onwards. Did hte following to fix my problem

//Retrive and store previous Class context.
ClassLoader prevCl = Thread.currentThread().getContextClassLoader();

try{

// Get the current classes Class loader info
ClassLoader classcl = this.getClass().getClassLoader();

//Set class context loader to the current thread
Thread.currentThread().setContextClassLoader(classcl);

Hashtable env = new Hashtable(5, 0.75F);
env.put(Context.INITIAL_CONTEXT_FACTORY,.....)
....

DirContext ctx = new InitialDirContext(env)

}catch(Exception e) {
....
} finally {
// Restore
Thread.currentThread().setContextClassLoader(prevCl);
}

Mods. This thread can be closed now.

Thanks
Sandesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot instantiate class: