Beruflich Dokumente
Kultur Dokumente
Start Eclipse.
1
Name the Project SimpleEjb3Project.
Check Add project to an EAR. This will create a separate Project for deployment.
Click Next.
2
We will not use a Client Project for this simple example.
Click Finish.
3
We will create a very simple application with 1 EJB Stateless Session Bean and create a
standalone client for a test.
4
Create a new Package.
5
Create a new Interface.
Name it SimpleRemote.
6
Add the following.
package ejbs;
import javax.ejb.Remote;
@Remote
public interface SimpleRemote {
7
Create a new Class.
8
Name the Class SimpleBean.
Implement SimpleRemote.
9
Add the following.
package ejbs;
import javax.ejb.Stateless;
@Stateless(name="SimpleBean", mappedName="ejb/SimpleBean")
public class SimpleBean implements SimpleRemote {
10
Create a new Package named tests.
11
Create a new Class to test the EJB named TestEjb.
12
Add the following.
package tests;
import javax.naming.Context;
import javax.naming.InitialContext;
import ejbs.SimpleRemote;
/**
* @param args
*/
public static void main(String[] args)
throws Exception {
13
Create a new Source Folder named resources.
14
Create a new file named jndi.properties.
15
Add the following.
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
16
Create another file named log4j.properties.
17
Add the following.
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
18
Clean and Build the Project.
19
Start the Server.
20
Deploy the application.
21
Run the Test.
22
You should see the following.
23