【问题标题】:JNDI: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactoryJNDI:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory
【发布时间】:2017-06-23 23:16:04
【问题描述】:

板上已经有一个类似的问题,但是建议的解决方案代码对我不起作用。我想通过使用 Java 消息服务和 Wildfly 10 应用程序服务器来实现一个简单的聊天程序 (jms pub/sub)。我在 Eclipse 中配置并启动了服务器(状态:已启动,已同步)。当我编译只包含一个类的程序时,会出现以下错误消息:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory] at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at javax.naming.InitialContext.<init>(Unknown Source) at Chat.<init>(Chat.java:55) at Chat.main(Chat.java:128) Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source) at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source) ... 6 more

我不认为代码中的JNDI属性有什么问题(我尝试了几个派生):

Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,         
"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:9090");
jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);

wildfly 10 jar 和 jms.jar 一起添加到项目路径中

还有什么可能导致错误?

编辑:

我尝试使用 maven,因为我认为有些 jar 无法识别。我在我的 pom 文件中添加了 wildfly10 和 jms:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>mannheim</groupId>
      <artifactId>hello</artifactId>
      <version>0.0.1-SNAPSHOT</version>



      <dependencies>
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-ejb-client-bom</artifactId>
            <version>10.0.0.Final</version>
        </dependency>
      </dependencies>
    </project>

在 pom 文件中说明了这两个依赖项:

缺少工件 javax.jms:jms:jar:1.1

所以我猜在识别 jar.files 方面仍然存在问题?

【问题讨论】:

  • 你有没有尝试添加'jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");'在你的 jndi 属性上?
  • 我将它添加到属性中,但仍然收到此错误:“javax.naming.NoInitialContextException:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory”
  • 我认为您缺少 jboss-client.jar 文件?它在wildfly/bin/client下

标签: jboss jms jndi factory


【解决方案1】:

【讨论】:

  • 还是同样的错误。我现在尝试使用 maven,但我在 pom 文件中收到另一条错误消息。也许这就是原因(见编辑后的帖子)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 2022-01-03
  • 1970-01-01
  • 2011-08-14
  • 2018-09-05
  • 2020-11-06
  • 2015-06-23
相关资源
最近更新 更多