JNDI:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory

时间:2017-06-21 17:02:04

标签: jboss jms jndi factory

董事会已经有类似的问题,但是建议的解决方案代码对我不起作用。我想通过使用Java Messaging Service和Wildfly 10 Application Server来实现一个简单的聊天程序(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,因为我认为某些罐子无法识别。我将wildfly10和jms添加到我的pom文件中:

    <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仍有问题吗?

1 个答案:

答案 0 :(得分:0)