TP3 Framework de Dev JEE
TP3 Framework de Dev JEE
1 Préparation de l’environnement
1. Environment Used
§ JDK 7 (Java SE 7)
§ EJB 3.0
§ Eclipse
§ JBoss Tools – Core 4.4.1 M5 for Eclipse
§ JBoss Application Server (AS) 7.1.0 Final
2. Installing JDK
JDK should be installed with proper environment set up. Read this page for installing the
JDK and setting up the environment.
1/9
7. Configuring JBoss AS in Eclipse IDE
Open Eclipse IDE
Add Server
Make sure you are in Java EE perspective and in “Servers” area, right click -> New ->
Server.
Here you will see list of servers that can be configured in the installed Eclipse version. You
will find JBoss AS 7.1 under “JBoss Community” as shown below.
2/9
Configuring JBoss AS location
8. Finish
Make sure the runtime information is correct and click Finish.
The configured JBoss AS will be displayed in the “Servers” view.
3/9
9. Start Server
It is easy to manage the server instance. Right-click on the server and start and stop it to
ensure its proper working.
4/9
2 EJB session stateless
1. Créer un nouveau projet EJB 3.1 : EJBSessionStateless
5/9
3. Implémenter les trois méthodes add(), mult() et Say() du bean Calculator
@Stateless
@LocalBean
public class Calculator implements CalculatorRemote, CalculatorLocal {
/**
* Default constructor.
*/
public Calculator() {
// TODO Auto-generated constructor stub
}
6/9
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL,"remote://127.0.0.1:4447");
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLIC
Y_NOPLAINTEXT", "false");
//properties.put(Context.SECURITY_PRINCIPAL, "root");
//properties.put(Context.SECURITY_CREDENTIALS, "password");
return new InitialContext(properties);
7/9
System.out.println("Multiplication " + num2 + " time " + num1 + " via the
remote stateless calculator deployed on the server");
float mult = statelessRemoteCalculator.mult(num1, num2);
System.out.println("Remote calculator returned multiplication = " + mult);
public Counter() {
// TODO Auto-generated constructor stub
}
@Override
public void increment() {
this.count++;
}
@Override
public void decrement() {
this.count--;
}
@Override
public int getCount() {
return this.count;
}
8/9
// now decrementing
System.out.println("Counter will now be decremented " + NUM_TIMES + " times");
for (int i = NUM_TIMES; i > 0; i--) {
System.out.println("Decrementing counter");
statefulRemoteCounter.decrement();
System.out.println("Count after decrement is " +
statefulRemoteCounter.getCount());
}
}
4. Suivre les mêmes étapes que le session bean stateless pour invoquer ce bean par
un client Java.
9/9