JNDI“无法实例化类:org.jboss.naming.remote.client.InitialContextFactory” [英] JNDI "Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory"
本文介绍了JNDI“无法实例化类:org.jboss.naming.remote.client.InitialContextFactory”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
控制台应用程序代码看起来像这样
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Program {
public static void main(String [] args)throws NamingException {
// TODO自动生成的方法存根
属性pr = new Properties();
(.net)
pr.put(InitialContext.PROVIDER_URL,remote:// localhost:4447);
InitialContext ic = new InitialContext(pr);
}
}
当我运行应用程序我得到异常
线程main中的异常javax.naming.NoInitialContextException:无法实例化类:org.jboss.naming .remote.client.InitialContextFactory [根异常是java.lang.ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory]
在javax.naming.spi.NamingManager.getInitialContext(未知来源)
在javax.naming.InitialContext.getDefaultInitCtx(未知源)
在javax.naming.InitialContext.init(未知源)
在javax.naming.InitialContext。< init>(未知来源)
在Program.main(Program.java:14)
导致:java.lang.ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory
在java.net.URLClassLoader $ 1.run(未知源)
在java.net.URLClassLoader $ 1.run(未知源)
在java.security.AccessController.doPrivileged(本机方法)
在java.net.URLClassLoader.findClass(未知来源)
在java.lang.ClassLoader.loadClass(未知来源)
在sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)
在java.lang.ClassLoader.loadClass(未知源)
在java.lang.Class.forName0(本机方法)
在java.lang.Class.forName(未知来源)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 5更多
解决方案
您可以使用以下上下文进行连接。
我已经尝试并测试了设置这个。
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
public class Program {
public static void main(String [] args)throws NamingException {
属性jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
org.jboss.naming.remote.client.InitialContextFactory);
jndiProps.put(Context.PROVIDER_URL,remote:// localhost:4447);
jndiProps.put(Context.SECURITY_PRINCIPAL,testuser);
jndiProps.put(Context.SECURITY_CREDENTIALS,testpassword);
jndiProps.put(jboss.naming.client.ejb.context,true);
上下文ctx = new InitialContext(jndiProps);
}
}
然后我得到这个错误
JBREM000200:远程连接失败:javax.security.sasl.SaslException:
验证失败:所有可用的验证机制失败 - 可能
未注册用于连接到远程的EJB接收器:// localhost:4447
java.lang.RuntimeException:javax.security.sasl.SaslException:验证
失败:所有可用的身份验证机制失败。
然后我添加了使用add-user.sh的用户。
成功握手消息。
I'm using JBoss Server for EJB And I need JNDI in console app to get reference of session bean, console app code looks like this
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Program {
public static void main(String[] args) throws NamingException {
// TODO Auto-generated method stub
Properties pr = new Properties();
pr.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
pr.put(InitialContext.PROVIDER_URL,"remote://localhost:4447");
InitialContext ic = new InitialContext(pr);
}
}
when I run the application I get exception
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 Program.main(Program.java:14)
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)
... 5 more
解决方案
You can use following context to connect. I have tried and tested to set up this.
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
public class Program {
public static void main(String[] args) throws NamingException {
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
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);
}
}
Then i got this error
JBREM000200: Remote connection failed: javax.security.sasl.SaslException:
Authentication failed: all available authentication mechanisms failed - Could
not register a EJB receiver for connection to remote://localhost:4447
java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication
failed: all available authentication mechanisms failed.
Then i added the user using add-user.sh.
Successful Handshake message came.
这篇关于JNDI“无法实例化类:org.jboss.naming.remote.client.InitialContextFactory”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文