English 中文(简体)
Running standalone Glassfish v3 client as Eclipse plugin
原标题:

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 naming 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");  




相关问题
Run EXE from client side

I need run an exe file from client side. The Exe file exist in my C: Directory. I need run this exe file from my WEB site. How can I co this?

Security in PHP

I ve written some PHP scripts to do some server-side work on a headless linux server machine on a LAN. For example, I have http://ipadress/php/operations.php?operation=registerUser&uName=X&...

EMAIL server FSP model

For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...

Calling a service from a callback method in Client

I have a scenario where, upon receiving a command on one of the callback methods in client, the client needs to call another service. For example: In OnNewCommand() callback method client receives a ...

ServiceContractGenerator vs ServiceDescriptionImporter

I m trying to build a light-weight SOAP client without using Add Service Reference. Ideally, this client should work for as many services as possible. Currently, it uses ServiceDescriptionImporter to ...

Simple server and client request/response in C#

OK. I just want to know if this can be done. I m using C# asp.net language. I want to send a structure to a webserver from a webpage (much like you you can pass a structure to a function). The ...

热门标签