Bonjour ,
je viens de débuter EJB mais dans tout les exemples que j'ai essyé je me trouve toujours sur l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.init(InitialContext.java:242)
	at javax.naming.InitialContext.<init>(InitialContext.java:216)
	at tests.TestEjb.main(TestEjb.java:28)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
	... 4 more
Mon Client est
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tests;
import java.util.Properties;
 
import javax.naming.Context;
import javax.naming.InitialContext;
 
import ejbs.SimpleRemote;
 
public class TestEjb {
 
	/**
         * @param args
         */
	public static void main(String[] args) 
		throws Exception {
 
		String jndiName = "java:global/Teste/SimpleBean";
		Context context ;
		Properties properties = new Properties();
		properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"
		);
		properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
		properties.put("java.naming.provider.url","localhost:1099");
 
		try
		{
		 context = new InitialContext(properties);
		System.out.println("Looking up JNDI Name " + jndiName);
		Object object = context.lookup(jndiName);
		System.out.println("Lookup returned " + object);
 
		SimpleRemote remote = (SimpleRemote) object;
		System.out.println(remote.getMessage());
		}
		catch(Exception e)
 
		{
		e.printStackTrace();
		}
	}}
mon bean est
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
package ejbs;
 
import javax.ejb.EJB;
import javax.ejb.Stateless;
 
@Stateless(name="SimpleBean", mappedName="SimpleBean")
public class SimpleBean implements SimpleRemote {
 
	public String getMessage() {
		return "Hello from EJB 3.0";
	}
 
}
mon interface
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
package ejbs;
 
import javax.ejb.Remote;
 
@Remote
public interface SimpleRemote {
 
	public String getMessage();
}