1

OSGi client tries to connect to GF4. In maven I added gf-client-module 4. I see that bundle glassfish-naming-4.0.jar is installed.

So in Activator I have.

ClassLoader thatLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
       Properties jndiProps = new Properties();
       jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
       jndiProps.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
       jndiProps.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
       jndiProps.setProperty("org.omg.CORBA.ORBInitialHost", "x.x.x.x");
       jndiProps.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
       InitialContext ctx = new InitialContext(jndiProps);
} finally {
Thread.currentThread().setContextClassLoader(thatLoader);
}

And this is what I get

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]

How can it be fixed? Bundle glassfish-naming-4.0.jar has Activator inside. Should I start this bundle? I tried but got unresolved constraints exception.

Solution SerialInitContextFactory not found in glassfish naming didn't help.

2 Answers 2

2

I found the solution. As I understood glassfish-naming,gf-client-module and other osgi bundles are bundles that belong to glassfish! If I want to to use gf-client I must do:

1) Copy the as-install/lib/gf-client.jar file to the client machine and include it in the classpath on the client side.

The gf-client.jar file references GlassFish Server JAR files in its MANIFEST.MF file. If there is no GlassFish Server installation on the client machine, 2) you must also copy the as-install/modules directory to the client machine and maintain its directory structure relative to the as-install/lib/gf-client.jar file. Or you can use the package-appclient script; see Using the package-appclient Script.

This is from http://docs.oracle.com/cd/E18930_01/html/821-2418/gkusn.html

Sign up to request clarification or add additional context in comments.

2 Comments

there's also the appclient command. Can appclient just "copy over" all of these glassfish JARS for inclusion on the classpath as a lib?
This. When including gf-client.jar the client has to ensure it's in the whole glassfish folder, not just a standalone file! Guess I overlooked it.
0

You need to make the com.sun.enterprise.naming.SerialInitContextFactory available to your bundle classloader. Make sure you have a Import-Package: com.sun.enterprise.naming in your bundle's Manifest.

If you use the maven bundle plugin then it will figure out most imports automatically. In this case though the class is only given as a String so it will not see it. An alternative is to use the class.getName instead of the String like this: com.sun.enterprise.naming.impl.SerialInitContextFactory.class.getName()

Btw. thwe same applies to com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl

5 Comments

I added to maven dependency gf-client-module and glassfish-naming but it didn't help
I am not talking about maven dependencies. The bundle classpath is defined only at runtime and needs a correct Manifest. How do you create your bundle Manifest? Using the maven bundle plugin?
Yes, using maven bundle plugin Please, say do you use osgi+gf client with gf-client-module?
No but I attached to weblogic some time ago which is similar I think. For the maven bundle plugin add Import-Package instructions to the config in the pom for the packages com.sun.enterprise.naming.impl and com.sun.corba.ee.impl . Hopefully these are exported by the gf client module
Thank you for your time. I found the solution and posted id as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.