【问题标题】:java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory errorjava.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory 错误
【发布时间】:2015-03-25 00:30:58
【问题描述】:

我正在尝试将我的客户端应用程序连接到 JBoss 7.1.1。 MHSessionBeanRemote 是我的服务器端 bean 类。

我的班级代码

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class MHSessionBeanClient {
    public static void main(String[] args) throws NamingException {
        Context context = MHSessionBeanClient.getInitialContext();
        MHSessionBeanRemote mhSessionBean = (MHSessionBeanRemote)context.lookup("MHSessionBean/remote");
        mhSessionBean.mhSessionBeanMethod();
    }   
    public static Context getInitialContext() throws NamingException {
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        properties.put(Context.PROVIDER_URL,"remote://127.0.0.1:4447");
        properties.put(Context.SECURITY_PRINCIPAL, "user");
        properties.put(Context.SECURITY_CREDENTIALS, "password");
        properties.put("jboss.naming.client.ejb.context", true);
        return new InitialContext(properties);
    }
}

和错误:

Exception in thread "main" 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 MHSessionBeanClient.getInitialContext(MHSessionBeanClient.java:25)
at MHSessionBeanClient.main(MHSessionBeanClient.java:12)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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

我做错了什么?

【问题讨论】:

标签: class jboss jboss7.x


【解决方案1】:

仅供参考, 如果您使用 WildflyJMS,请将 wildfly-jms-client-bom 添加到您的 pom 中;

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-jms-client-bom</artifactId>
        <version>10.0.0.Final</version>
        <type>pom</type>
    </dependency>

【讨论】:

    猜你喜欢
    • 2014-09-01
    • 1970-01-01
    • 2013-07-23
    • 2016-03-14
    • 2020-01-22
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    相关资源
    最近更新 更多