Bonjour tout le monde .

Tout d'abord excusez-moi si je ne suis pas dans le bon salon du forum :/!

Je vais vous mettre mon code serveur et code client en dessous.

Mon problème est :
!!!!! ERROR : 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 !!!!!
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:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Main.main(Main.java:16)
Donc il me manque "java.naming.factory.initial", j'ai fait des recherches mais soit je n'ai pas la bonne librairie ou la bonne propriété par exemple valeur du factory:"com.ibm.websphere.naming.WsnInitialContextFactory", mais il ne la trouve pas....

Si vous avez des idées et explication à donner je suis un grand preneur de ce genre de chose ^^.

Donc le EJB est déployé sur Websphere 8.5 via MyEclipse Blue.

Mon but final après plusieurs test est de mélanger plusieurs ejb avec etat, sans état, entity et singleton pour mon plus grand plaisir .

Côté serveur:
Interface local
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
package simpleejb;
 
import javax.ejb.Local;
 
/**
 * SimpleEJB local interface
 */
@Local
public interface SimpleEJBLocal {
	int addLocal(int a, int b);
	int multiLocal(int a, int b);
}
Interface Remote
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
package simpleejb;
 
import javax.ejb.Remote;
 
@Remote
public interface SimpleEJBRemote {
	int addRemote(int a, int b);
	int multiRemote(int a, int b);
}
[COLOR ="red"] SimpleEJB[/COLOR]
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
41
package simpleejb;
 
import javax.ejb.Stateless;
 
/**
 * Session Bean implementation class SimpleEJB
 */
@Stateless
public class SimpleEJB implements SimpleEJBLocal, SimpleEJBRemote {
 
	/**
     * Default constructor. 
     */
    public SimpleEJB() {
 
    }
 
	@Override
	public int addRemote(int a, int b) {
		System.out.println("+++++++ Remote add +++++++");
		return a+b;
	}
 
	@Override
	public int multiRemote(int a, int b) {
		System.out.println("******* Remote multi *******");
		return a*b;
	}
 
	@Override
	public int addLocal(int a, int b) {
		System.out.println("+++++++ Local add +++++++");
		return a+b;
	}
 
	@Override
	public int multiLocal(int a, int b) {
		System.out.println("******* Local multi *******");
		return a*b;
	}
}

EJB-jar.xml


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
  <display-name>SimpleEJB </display-name>
  <!--  <ejb-client-jar>SimpleEJBClient.jar</ejb-client-jar> -->
</ejb-jar>

Côté Client:

MAIN

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
 
import java.util.Properties;
 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
 
 
public class Main {
	public static void main(String[] args) {
		Properties proprietes = new Properties();
		proprietes.setProperty(Context.PROVIDER_URL, "corbaloc:iiop:127.0.0.1:2810");  // localisation du serveur d'applications dans le réseau local de l'entreprise
		//proprietes.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
		Context ctx;
		try {
			ctx = new InitialContext(proprietes);
			SimpleEJBRemote foo = (SimpleEJBRemote) ctx.lookup("java:global/SimpleEJB/ejbmodule/simpleejb.SimpleEJB!simpleEJB.SimpleEJBRemote");
			System.out.println("!!!!!!! Reponse ADD :" + foo.addRemote(2, 3));
		} catch (NamingException e) {
			System.out.print("!!!!! ERROR : " + e.getMessage() + " !!!!!\n");
			e.printStackTrace();
		}	
	}
}