Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Using JNDI in a plugin project
Using JNDI in a plugin project [message #272667] Fri, 24 September 2004 19:56 Go to next message
Ian Phillips is currently offline Ian PhillipsFriend
Messages: 79
Registered: July 2009
Member
I'm trying to write a plugin which uses JNDI (to get at JMS
administered objects), the ClassLoader seems to be doing wierd things
which prevent it from working.

I have 2 plugins: one is just a container for a vendor supplied JAR
file, the other is my project. At first I thought that maybe I'd
screwed up my manifest (using OSGi style plugins) but now I'm not sure.
I've tried this code:

try {
Class a =
Class.forName("com.evermind.server.ApplicationClientInitialContextFactory ");


Object o = a.newInstance();
System.out.println("o: " + o);
System.out.println("a loader: " + a.getClassLoader());
System.out.println("b loader: " +
this.getClass().getClassLoader());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
context = new InitialContext(props);
System.out.println("context: " + context);
return context;
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}

and get this result:

o: com.evermind.server.ApplicationClientInitialContextFactory@7ab1ba
a loader: org.eclipse.core.runtime.adaptor.EclipseClassLoader@8e31e
b loader: org.eclipse.core.runtime.adaptor.EclipseClassLoader@f08d6f
javax.naming.NoInitialContextException: Cannot instantiate class:
com.evermind.server.ApplicationClientInitialContextFactory [Root
exception is java.lang.ClassNotFoundException:
com.evermind.server.ApplicationClientInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManag er.java:652)


I'm confused as to why 2 different ClassLoaders are being used, if
anybody has any pointers or suggestions I'd be grateful.

Ian.

--
#ifndef __COMMON_SENSE__ | Ian Phillips
#include <std_disclaimer> | http://ianp.org
#endif
Re: Using JNDI in a plugin project [message #272703 is a reply to message #272667] Sun, 26 September 2004 12:10 Go to previous message
Eclipse UserFriend
Originally posted by: igorf.ca.ibm.com

You need to set thread context classloader before calling JNDI. It's
been a while since I looked at eclipse classloading, but I believe it
creates separate classloader for each plugin and uses delegation to load
classes from required plugins.

Ian Phillips wrote:

> I'm trying to write a plugin which uses JNDI (to get at JMS administered
> objects), the ClassLoader seems to be doing wierd things which prevent
> it from working.
>
> I have 2 plugins: one is just a container for a vendor supplied JAR
> file, the other is my project. At first I thought that maybe I'd screwed
> up my manifest (using OSGi style plugins) but now I'm not sure. I've
> tried this code:
>
> try {
> Class a =
> Class.forName("com.evermind.server.ApplicationClientInitialContextFactory ");
>
>
>
> Object o = a.newInstance();
> System.out.println("o: " + o);
> System.out.println("a loader: " + a.getClassLoader());
> System.out.println("b loader: " +
> this.getClass().getClassLoader());
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> try {
> context = new InitialContext(props);
> System.out.println("context: " + context);
> return context;
> } catch (NamingException e) {
> e.printStackTrace();
> throw new RuntimeException(e);
> }
>
> and get this result:
>
> o: com.evermind.server.ApplicationClientInitialContextFactory@7ab1ba
> a loader: org.eclipse.core.runtime.adaptor.EclipseClassLoader@8e31e
> b loader: org.eclipse.core.runtime.adaptor.EclipseClassLoader@f08d6f
> javax.naming.NoInitialContextException: Cannot instantiate class:
> com.evermind.server.ApplicationClientInitialContextFactory [Root
> exception is java.lang.ClassNotFoundException:
> com.evermind.server.ApplicationClientInitialContextFactory]
> at
> javax.naming.spi.NamingManager.getInitialContext(NamingManag er.java:652)
>
>
> I'm confused as to why 2 different ClassLoaders are being used, if
> anybody has any pointers or suggestions I'd be grateful.
>
> Ian.
>
Previous Topic:Moving a Java file (refactor) doesn't work
Next Topic:Is org.eclipse.jface.text.GapTextStore meant to be used for large Strings?
Goto Forum:
  


Current Time: Fri Oct 18 11:41:42 GMT 2024

Powered by FUDForum. Page generated in 0.07177 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top