| Classloader problems creating J2EE RemoteHome within plugin [message #215705] | 
Thu, 25 March 2004 07:57   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: jonathan_oconnor.hotmail.com 
 
Hi, 
I'm trying to access our JBoss J2EE server from within a plugin. 
Due to class loading problems, I'm not having a lot of success. 
Does anyone have any code that actually works? 
 
This is what I have currently: 
public static FolderHome getHome() { 
    ClassLoader oldClassLoader = 
Thread.currentThread().getContextClassLoader(); 
    try { 
        // JNDI uses the context classloader to load classes by name 
        Thread.currentThread().setContextClassLoader(null); 
        if (home == null) { 
            if (ctx == null) { 
                Hashtable env = new Hashtable(); 
                env.put("java.naming.factory.initial", 
"org.jnp.interfaces.NamingContextFactory"); 
                env.put("java.naming.factory.url.pkgs", 
"org.jboss.naming:org.jnp.interfaces"); 
                env.put("java.naming.provider.url", "jnp://localhost:1099"); 
                env.put("java.naming.rmi.security.manager", "yes"); 
                NamingContextFactory namingFactory = new 
NamingContextFactory(); 
                ctx = namingFactory.getInitialContext(env); 
                //ctx = new InitialContext(env); 
            } 
            home = (FolderHome) PortableRemoteObject.narrow(ctx 
                                .lookup(FolderHome.JNDI_NAME), 
FolderHome.class); 
        } 
    } catch (Exception e) { 
        e.printStackTrace(System.out); 
    } finally { 
        // reset the context classloader 
         Thread.currentThread().setContextClassLoader(oldClassLoader) ; 
    } 
    return home; 
} 
 
And I get the following stacktrace (well I'll only bore you with the start 
of it): 
javax.naming.CommunicationException [Root exception is 
java.lang.ClassNotFoundException: de/xcom/emv/server/interfaces/FolderHome 
(no security manager: RMI class loader disabled)] 
    at  org.jnp.interfaces.NamingContext.lookup(NamingContext.java:6 34) 
    at  org.jnp.interfaces.NamingContext.lookup(NamingContext.java:4 72) 
    at 
 de.xcom.SpikeJBPlugin.jbclient.FolderBeanUtil.getHome(Folder BeanUtil.java:62 
) 
    at 
de.xcom.SpikeJBPlugin.actions.SampleAction.<init>(SampleAction.java:42) 
    at  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method) 
    at 
 sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAcces 
sorImpl.java:39) 
    at 
 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstruc 
torAccessorImpl.java:27) 
    at  java.lang.reflect.Constructor.newInstance(Constructor.java:2 74) 
    at java.lang.Class.newInstance0(Class.java:308) 
    at java.lang.Class.newInstance(Class.java:261) 
    at 
 org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutableExte 
nsion(ConfigurationElement.java:143) 
    at 
 org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutableExte 
nsion(ConfigurationElement.java:125) 
    at 
 org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutableExte 
nsion(ConfigurationElement.java:114) 
    at 
 org.eclipse.ui.internal.WorkbenchPlugin$1.run(WorkbenchPlugi n.java:171) 
 
Caused by: java.lang.ClassNotFoundException: 
de/xcom/emv/server/interfaces/FolderHome (no security manager: RMI class 
loader disabled) 
    at  sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.ja va:531) 
    at 
 java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoad er.java:639) 
    at 
 java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader .java:309) 
    at 
 sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalI nputStream.java: 
241) 
    at  java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.ja va:1469) 
    at  java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1432) 
    at 
 java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1626) 
    at  java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1274) 
    at  java.io.ObjectInputStream.readObject(ObjectInputStream.java: 324) 
    at java.rmi.MarshalledObject.get(MarshalledObject.java:135) 
    at 
 org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePa ir.java:30) 
    at  org.jnp.interfaces.NamingContext.lookup(NamingContext.java:5 15) 
    ... 39 more 
 
Thanks, 
Jonathan O'Connor 
XCOM AG
 |  
 |  
  | 
| Re: Classloader problems creating J2EE RemoteHome within plugin - Workaround [message #215715 is a reply to message #215705] | 
Thu, 25 March 2004 08:52   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: jonathan_oconnor.hotmail.com 
 
Folks, 
I found the answer. Yes it was a problem with the classloader, but I've 
worked around it. The trick is not use InitialContext. 
Instead you should create an instance of the class referred to by the 
java.naming.factory.initial property. Just call getInitialContext(env) on 
this and bingo, it all works. 
public static FolderHome getHome() { 
    try { 
        if (home == null) { 
            if (ctx == null) { 
                Hashtable env = new Hashtable(); 
                env.put("java.naming.factory.initial", 
"org.jnp.interfaces.NamingContextFactory"); 
                env.put("java.naming.factory.url.pkgs", 
"org.jboss.naming:org.jnp.interfaces"); 
                env.put("java.naming.provider.url", "jnp://localhost:1099"); 
                env.put("java.naming.rmi.security.manager", "yes"); 
                NamingContextFactory namingFactory = new 
NamingContextFactory(); 
                ctx = namingFactory.getInitialContext(env); 
                //ctx = new InitialContext(env); 
            } 
            home = (FolderHome) 
 PortableRemoteObject.narrow(ctx.lookup(FolderHome.JNDI_NAME) , 
FolderHome.class); 
        } 
    } catch (ClassCastException e) { 
        e.printStackTrace(System.out); 
    } catch (NamingException e) { 
        e.printStackTrace(System.out); 
    } 
    return home; 
} 
 
You'll also need jbossall-client.jar and log4j.jar as part of your runtime 
jars. 
 
Have fun, 
Jonathan
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.11814 seconds