Create a New Project (Main Menu | File | New Project). Enter "HelloWorld" as the project name. As you won't need standard libraries, remove them from the project: press Advanced button, select Search Classpath and make sure that checkboxes 'Include standard libraries' and 'Include Classpath' are cleared. Press OK button.
Create a New Package. Set name to "hello" and choose Open in New Tab from the speedmenu.
Click on 'Session EJB' icon and create a session bean in the "hello" package. Name it "HelloBean".
Create business method ( New | Business Method on the bean speedmenu). Choose created method in the bean shape and enter hello:String instead of method1:void. Add the following code to this method in the Text Editor:
public String hello(){ System.out.println("hello()"); return "Hello World"; }
Note: Make sure that return types of hello() method in the "HelloBean" and in "Hello" are identical (String).
The bean is now ready for deployment to WebSphere 3.5.
Start WebSphere Server 3.5 services from Control Panel | Services.
Run Together's Main Menu | Tools | EJB Deployment Expert
Select IBM WebSphere AE 3.5 as the target server and make sure that all available checkboxes, except for "Process servlets", "Generate WLM jar for Bean","Generate start and compile file for client" and "Generate simple JSP client", are set.
Specify correct paths to WebSphere home directory and to IBM JDK 1.2.2 root directory (e.g. c:\WebSphere\AppServer and c:\WebSphere\AppServer\jdk), and press Next.
Set the following parameters on the next page:
|
Parameter name |
Setting |
Comment |
|
Admin Node Name |
Name of the Node to deploy |
Name of the computer |
|
Application Server Name |
Your Application Server |
"Default Server" by default |
|
EJB Container name |
Your Container name |
"Default Container" by default |
|
Target WebSphere server directory |
WebSphere home directory |
e.g. c:\WebSphere\AppServer |
|
Launch server in debug mode |
OFF |
|
Press Next and Finish.
If you have checked Hot Deploy check box, the last message in the
Message Pane should be:
//WAS35: Finished with 0 Errors, 0 Warnings.
It means the deployment process successfully completed. Let's now proceed with creating a client.
By now you have a project with HelloWorld Session bean, which is deployed to WebSphere Server 3.5.
Create two New Packages on the default diagram. Set name of the first package to "client", and the name of the other package to "WebSphere". Open each package in new tab (choose Open in New Tab on the speedmenu of each package).
Create main class in the "WebSphere" package using Class by Pattern icon. Select Main Class pattern, change name to HelloClient and press Finish button.
Add the following code to your main method:
public static void main(String[] argv) {
try{
Properties props = System.getProperties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
props.put(Context.PROVIDER_URL,
"iiop://localhost:900");
Context ctx = new InitialContext(props);
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("hello/HelloHome"),HelloHome.class);
Hello hello = home.create();
System.out.println(hello.hello());
hello.remove();
Add the following import statements:
import javax.naming.*;
import java.util.Properties;
import hello.*;
The client is now ready for compiling and running.
Add the following libraries to your project:
%WAS_HOME%\jdk\jre\lib\ext\rmiorb.jar
%WAS_HOME%\jdk\jre\lib\ext\iioprt.jar
Deployed jar file (e.g. %WAS_HOME%\deployableEJBs\DeployabletogetherEJB.jar)
Home directory of WebSphere Server %WAS_HOME%This is done in the following way
From the Main Menu | File | Project Properties dialog select
Search/Classpath page on the Resource pane. At this moment there
shouldn't be anything added to the classpath.
Press Add Zip/JAR button and add %WAS_HOME%\jdk\jre\lib\ext\rmiorb.jar,
%WAS_HOME%\jdk\jre\lib\ext\iioprt.jar
Press OK to save project properties.
Select Main Menu | Options | Project
Go to the Tools tab and add Deployed jar file to the ClassPath.
Select Main Menu | Options | Project and set JDK Home to %WAS_Home%\jdk on the Tools Tab.
Select HelloClient class
and choose Rebuild Node on its speedmenu.
The Message pane displays a message that the tool
is completed.
Select Tools | Run/Debug | Run from the main menu and see "Hello World" message in the Message pane and "hello()" in the server console.