javax.naming.NoInitialContextException: Need to specify class name
Bonjour voila, je débute avec les EJB. La première étape de mon apprentissage et de créer un ejb Session de type Stateless qui a pour but simplement de d'afficher du texte.
Environnement -> Eclipse , Jboss
Donc j'ai 3 fichiers sources dans mon paquetage "texte":
- MsgText qui est l'interface distante,
- MsgTextHome qui est l'interface locale,
- et bien evidement une classe MsgTextBean qui étend EJBSession
Voici mon ejb-jar.xml qui se trouve dans le dossier META-INF
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description></description>
<enterprise-beans>
<session>
<display-name>Descripteur de deploiement de MsgText</display-name>
<ejb-name>MsgText</ejb-name>
<home>texte.MsgTextHome</home>
<remote>texte.MsgText</remote>
<ejb-class>texte.MsgTextBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MsgText</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar> |
mon fichier jndi.properties
Code:
1 2 3
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099 |
PROBLEME au niveau du client :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static void main(String[] args) {
// TODO Auto-generated method stub
InitialContext namingContext = null;
try {
namingContext = new InitialContext();
} catch (NamingException e) {
System.err.println("Impossible d'acceder au contexte JNDI : " + e);
}
MsgTextHome home=null;
try {
home = (MsgTextHome)PortableRemoteObject.narrow(namingContext.lookup("MsgText"),MsgTextHome.class);
} catch (ClassCastException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}.... |
Erreur affichée :
Code:
1 2 3 4 5 6
| javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at Message.MsgTextClient.main(MsgTextClient.java:31) |