Take the following steps to deploy and run an EJB application using a J2EE server.
- Write code for a Remote interface and save the file as Welcome.java. The code for Welcome.java is given below:
import javax.ejb.*;
import java.rmi.RemoteException;public interface Welcome extends EJBObject
{
public String printMessage() throws RemoteException;
} - Write code for a Home interface and save the file as WelcomeHome.java. The code for Welcome.java is given below:
import javax.ejb.*;
import java.rmi.RemoteException;public interface WelcomeHome extends EJBHome
{
public Welcome create() throws CreateException, RemoteException;
} - Write code for a bean class and save the file as WelcomeBean.java. The code for WelcomeBean.java is given below:
import javax.ejb.*;
public class WelcomeBean implements SessionBean
{
public void ejbActivate()
{
System.out.println(”ejbActivate()”);
}public void ejbPassivate()
{
System.out.println(”ejbPassivate()”);
}public void ejbCreate()
{
System.out.println(”ejbCreate()”);
}public void ejbRemove()
{
System.out.println(”ejbRemove()”);
}public void setSessionContext(SessionContext ctx)
{
System.out.println(”setSessionContext()”);
}public String printMessage()
{
return “Welcome to your first EJB program. You have a long way to go.”;
}
} - Set up a directory structure as follows:

- Set the path and classpath in the environment. It is assumed that Java sdk is installed at the location C:jdk1.3 and j2ee sdk is installed at C:j2sdkee1.3.1.
The path should be set as C:jdk1.3bin,
The classpath should be set as C:j2sdkee1.3.1libj2ee.jar;C:j2sdkee1.3.1bin;C:WelcomeServJavaFile;C:WelcomeClient;C:WelcomeServclasses;.;
- Compile the Remote interface, the Home interface, the bean class, and the client file.
This will store the class files for the Remote interface, the Home interface, and the bean class in the classes folder. The class file for the client will be stored with the WelcomeClient.java file in the Client folder.
- Now open a new window on the command prompt and start the J2EE server using the j2ee -verbose command.

- Start the deploytool utility by typing deploytool in a new command prompt window.

A new application deployment tool screen will be displayed.
- To launch a new application, go to File>New>Application.

- A new application screen will be displayed. Enter the name of the application as C:WelcomeWelcomeApp.

- Now the application deployment screen will be displayed as shown below:

- To create a new JAR file, go to File>New>Enterprise Bean.

- A screen showing a new enterprise bean wizard will be displayed. From the combo box, select WelcomeApp. In the JAR display name, enter WelcomeApp. Then click the Edit button.

- A screen will be displayed showing the edit contents of the WelcomeAppJAR screen. Select the class files from the tree. For this, select Serv under the Welcome folder. Click the Add button. Then click the Ok button.

- A screen will be displayed that will prompt to choose the type of enterprise bean. Choose the Session bean radio button. Under the Session bean, choose the Stateless radio button.

- A screen will be displayed that will ask whether to use a Bean-Managed or Container-Managed transaction. Select the Bean-Managed radio button. Click the Finish button.

- To deploy the application, go to tools and click Deploy on the Application Deployment Tool screen.

- A screen will be displayed showing Deploy welcomeApp. Select welcomeApp in the Object to Deploy combo box. Select the Return Client Jar check box. Ensure that the client Jar file name is C:WelcomeWelcomeAppClient.jar. Click the Next button.

- A screen will be displayed asking for the JNDI name. Enter the name that was entered in the WelcomeClient code. The JNDI name in the code is WelcomeJNDI. Click the Finish button.

- The application will be deployed as shown below:

After the deployment is complete, click the Ok button.
- Now, the client needs to be packaged. In the Application Deployment Tool screen, go to File>New>Application Client.

- The New Application Client wizard screen will be displayed as shown below:

Click the Edit button.
- A screen saying Edit contents of Application client will be displayed.

- Now from the tree, choose WelcomeClient.class from Client under C:Welcome.

Click the OK button, and then click the Next button. Click the Finish button.
- Now it is time to run the application client. Open a new command prompt window. Go to C:Welcome. Set the path for the application client using set APPCPATH=WelcomeAppClient.jar. Press enter and then type the following command:
runclient -client WelcomeApp.ear -name WelcomeClient -textauth
The user will be asked to enter a user name and a password. Enter user name as user1 and password as user1. The printMessage() method will be invoked and the output will be displayed.

If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.

thanks for your notes……….