Server WildFly中的InitialContextFactory
我使用的是WildFly 10,JDK 8,不断出现以下错误: 严重:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory javax.naming.NoInitialContextException:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory[根异常为java.lang.ClassNotFoundException:org.jboss.naming.remote.client.InitialContextFactory] 我的代码是:Server WildFly中的InitialContextFactory,server,jboss,publish-subscribe,wildfly-10,point-to-point,Server,Jboss,Publish Subscribe,Wildfly 10,Point To Point,我使用的是WildFly 10,JDK 8,不断出现以下错误: 严重:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory javax.naming.NoInitialContextException:无法实例化类:org.jboss.naming.remote.client.InitialContextFactory[根异常为java.lang.ClassNotFoundException:org.jboss.naming.re
public class BuilderFactory {
private static final Logger log = Logger.getLogger(BuilderFactory.class.getName());
// Set up all the default values
private static final String INITIAL_CONTEXT_FACTORY =
"org.jboss.naming.remote.client.InitialContextFactory";
private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8085";
public static Context createContext(String userName, String password) {
Context namingContext = null;
try {
// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL,
PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
namingContext = new InitialContext(env);
return namingContext;
} catch (NamingException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
return namingContext; }}
正在尝试将此类作为主类运行:
public class SendMessage {
private static final Logger log = Logger.getLogger(SendMessage.class.getName());
// Set up all the default values
private static final String DEFAULT_MESSAGE = "Hello, World!";
private static final String DEFAULT_CONNECTION_FACTORY =
"jms/RemoteConnectionFactory";
private static final String DEFAULT_DESTINATION = "jms/queue/myQueue";
private static final String DEFAULT_MESSAGE_COUNT = "10";
private static final String DEFAULT_USERNAME = "jmsuser";
private static final String DEFAULT_PASSWORD = "Password1!";
public static void main(String[] args) {
Context namingContext = null;
try {
String userName = System.getProperty("username", DEFAULT_USERNAME);
String password = System.getProperty("password", DEFAULT_PASSWORD);
// Set up the namingContext for the JNDI lookup
namingContext = BuilderFactory.createContext(userName, password);
// Perform the JNDI lookups
String connectionFactoryString = System.getProperty("connection.factory",
DEFAULT_CONNECTION_FACTORY);
log.info("Attempting to acquire connection factory \"" +
connectionFactoryString + "\"");
ConnectionFactory connectionFactory = (ConnectionFactory)
namingContext.lookup(connectionFactoryString);
log.info("Found connection factory \"" + connectionFactoryString + "\" in
JNDI");
String destinationString = System.getProperty("destination",
DEFAULT_DESTINATION);
log.info("Attempting to acquire destination \"" + destinationString + "\"");
Destination destination = (Destination)
namingContext.lookup(destinationString);
log.info("Found destination \"" + destinationString + "\" in JNDI");
int count = Integer.parseInt(System.getProperty("message.count",
DEFAULT_MESSAGE_COUNT));
String content = System.getProperty("message.content", DEFAULT_MESSAGE);
try ( JMSContext context = connectionFactory.createContext(userName,
password) ) {
// Send the specified number of messages
for (int i = 0; i < count; i++) {
context.createProducer().send(destination, content);
System.out.println("Sending " + i + " messages with content: " +
content);
}
}
} catch (NamingException e) {
log.severe(e.getMessage());
e.printStackTrace();
} finally {
if (namingContext != null) {
try {
namingContext.close();
} catch (NamingException e) {
log.severe(e.getMessage());
}}}}}
公共类发送消息{
私有静态最终记录器log=Logger.getLogger(SendMessage.class.getName());
//设置所有默认值
private static final String DEFAULT_MESSAGE=“你好,世界!”;
私有静态最终字符串默认连接工厂=
“jms/RemoteConnectionFactory”;
私有静态最终字符串DEFAULT_DESTINATION=“jms/queue/myQueue”;
私有静态最终字符串默认\u消息\u COUNT=“10”;
私有静态最终字符串DEFAULT_USERNAME=“jmsuser”;
私有静态最终字符串DEFAULT_PASSWORD=“Password1!”;
公共静态void main(字符串[]args){
Context namingContext=null;
试一试{
字符串userName=System.getProperty(“用户名”,默认用户名);
字符串password=System.getProperty(“password”,默认密码);
//为JNDI查找设置namingContext
namingContext=BuilderFactory.createContext(用户名、密码);
//执行JNDI查找
String connectionFactoryString=System.getProperty(“connection.factory”,
默认连接(工厂);
log.info(“试图获取连接工厂\”+
connectionFactoryString+“\”);
ConnectionFactory ConnectionFactory=(ConnectionFactory)
查找(connectionFactoryString);
log.info(“在中找到连接工厂\”+connectionFactoryString+“\”
JNDI”);
String destinationString=System.getProperty(“目的地”,
默认目的地);
log.info(“试图获取目标\”“+目标字符串+”\”);
目的地=(目的地)
查找(destinationString);
log.info(“在JNDI中找到目的地\”“+destinationString+”\);
int count=Integer.parseInt(System.getProperty(“message.count”),
默认值(消息(计数));
String content=System.getProperty(“message.content”,默认消息);
try(JMSContext context=connectionFactory.createContext(用户名,
密码){
//发送指定数量的消息
for(int i=0;i
我刚刚找到了纠正此错误的解决方案!如果有人遇到这个问题,请右键单击项目来检查路径,选择库,并在编译时库中添加以下jar文件路径:您的类路径错误