开发者

Running standalone Glassfish v3 client as Eclipse plugin

开发者 https://www.devze.com 2022-12-18 06:49 出处:网络
I\'m developing a standalone client that invokes some EJB methods on Glassfish v3. This works well until I\'m integrating the client into an Eclipse plugin for running in our RCP application. In this

I'm developing a standalone client that invokes some EJB methods on Glassfish v3. This works well until I'm integrating the client into an Eclipse plugin for running in our RCP application. In this setting there seems to be a classloader problem on initializing the nam开发者_高级运维ing context and I get the exception listed below. (The client has gf-client.jar and all its dependencies on its classpath.)

It fails on

m_ctx = new InitialContext();

with the exception

java.lang.NoSuchMethodException: org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findResources(java.lang.String)
            at java.lang.Class.getMethod(Class.java:1605)
            at com.sun.enterprise.module.single.ManifestProxy.<init>(ManifestProxy.java:34)
            at com.sun.enterprise.module.single.ProxyModuleDefinition.<init>(ProxyModuleDefinition.java:78)
            at com.sun.enterprise.module.single.ProxyModuleDefinition.<init>(ProxyModuleDefinition.java:73)
            at com.sun.enterprise.module.single.SingleModulesRegistry.<init>(SingleModulesRegistry.java:42)
            at com.sun.enterprise.module.single.SingleModulesRegistry.<init>(SingleModulesRegistry.java:30)
            at com.sun.enterprise.module.single.StaticModulesRegistry.<init>(StaticModulesRegistry.java:60)
            at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:67)
            at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:183)
            at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:253)
            at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext(SerialInitContextFactory.java:121)
            at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:116)
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
            at javax.naming.InitialContext.init(InitialContext.java:223)
            at javax.naming.InitialContext.<init>(InitialContext.java:175)

Has anybody an idea how to solve this problem?


Further investigation of the Problem has shown, that Glassfishv3 relies on a public method findResources(java.lang.String) of the java.lang.Classloader.

package com.sun.enterprise.module.single;
[...]
public class ManifestProxy extends Manifest {
    [...]    
    public ManifestProxy(ClassLoader cl, List<SeparatorMappings> mappings) throws IOException {
        try {
           [...]
            Method met = cl.getClass().getMethod("findResources", String.class);
            Enumeration<URL> urls=null;
            try {
                met.setAccessible(true);
                urls = (Enumeration<URL>) met.invoke(cl, JarFile.MANIFEST_NAME);

But this method is protected in the Classloader class itself. When running the client as standalone java application the derived classloader sun.misc.Launcher$AppClassLoader is used which overrides this method and declares it public. But when running as Eclipse plugin the classloader org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader does not override the findResource-Method which leaves it protected and inaccessible by the ManifestProxy class.

What is the best way to solve this? How can I set a specific classloader for a eclipse plugin/osgi bundle?

Thanks!


I assume you using proper context settings?

    1. Properties props=new Properties();  
   2. props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");  
   3. props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");  
   4. props.setProperty("org.omg.CORBA.ORBInitialPort","3700");  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号