Il y a déjà une question similaire sur le tableau, mais le code de solution suggéré ne fonctionne pas pour moi. Je veux implémenter un programme de conversation simple (jms pub/sub) en utilisant Java Messaging Service et un serveur d'applications Wildfly 10. J'ai configuré et démarré le serveur en éclipse (status: Started, Synchronized). Quand je compile mon programm composé d'une seule classe, ce message d'erreur se produit:JNDI: Impossible d'instancier la classe: org.jboss.naming.remote.client.InitialContextFactory
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
Je ne pense pas qu'il y ait quelque chose de mal avec les propriétés JNDI dans le code (j'ai essayé plusieurs dérivés):
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);
le pot wildfly 10 est ajouté au chemin du projet, ainsi que la jms.jar
que peut-faire l'erreur?
Edit:
J'ai essayé d'utiliser maven parce que je pensais que certains pots ne sont pas reconnus. J'ai ajouté wildfly10 et jms à mon dossier 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>
Dans le fichier pom il est dit pour les dépendances:
artefact manquant javax.jms: jms: pot: 1.1
Il y a sont encore des problèmes avec la reconnaissance du jar.files je suppose?
Avez-vous essayé d'ajouter 'jndiProps.put (Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");' sur vos propriétés jndi? – likeachamp
je l'ai ajouté aux propriétés mais obtient toujours moi cette erreur: "javax.naming.NoInitialContextException: Impossible d'instancier la classe: org.jboss.naming.remote.client.InitialContextFactory" –
Je pense qu'il vous manque le fichier jboss-client.jar? il est sous wildfly/bin/client – likeachamp