java - InitialContext 的 OSGi 和 ClassNotFoundException

标签 java jakarta-ee glassfish ejb osgi

OSGi 客户端尝试连接到 GF4。在 Maven 中,我添加了 gf-client-module 4。我看到 bundle glassfish-naming-4.0.jar 已安装。

所以在 Activator 中我有。

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);
}

这就是我得到的

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

如何解决? bundle glassfish-naming-4.0.jar 里面有 Activator。我应该开始这个 bundle 吗?我尝试过,但遇到了 Unresolved 约束异常。

解决方案SerialInitContextFactory not found in glassfish naming没有帮助。

最佳答案

我找到了解决方案。据我了解,glassfish-naming、gf-client-module 和其他 osgi 包都是属于 glassfish 的包!如果我想使用 gf-client 我必须这样做:

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.

这是来自http://docs.oracle.com/cd/E18930_01/html/821-2418/gkusn.html

关于java - InitialContext 的 OSGi 和 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23464424/

相关文章:

Java 调试器有时看不到变量(通常在匿名内部类中)

java - Jdeveloper 未采用最新的编译文件

Java 应用程序服务器和 JVM

java - 在 Java EE 中绘制 google 图表

tomcat - 用于 Tomcat 和 Glassfish 的 META-INF/context.xml 文件

maven - glassfish 部署期间发生错误 - 此处没有默认名称的 Web 组件

java - JOGL透明背景

java - @NonNull 注释允许在验证中使用空值

java - 如何将实时变化的数据获取到本地服务器?

java - 在 tomcat 7 上运行 jersey servlet 的 servlet init 异常