Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Classloader problems creating J2EE RemoteHome within plugin
Classloader problems creating J2EE RemoteHome within plugin [message #215705] Thu, 25 March 2004 12:57 Go to next message
Eclipse UserFriend
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 13:52 Go to previous message
Eclipse UserFriend
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
Previous Topic:Eclipse not a standalone IDE
Next Topic:Eclipse 3.0M7 VE problem
Goto Forum:
  


Current Time: Mon Dec 30 17:09:12 GMT 2024

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

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

Back to the top