cancel
Showing results for 
Search instead for 
Did you mean: 

Deploy and run J2EE application client

Former Member
0 Kudos
92

Hi

I have developed a simple "hello World" EJB program and created a .jar (EJB archive). Next I have created .ear(Application archive) in a separate project and added the .jar file.

Now how and where I will write the application client( that will contain main() )and deploy and run the application which will show Hello world from the EJB .

Please help

Thanks in advance

Ananda

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

hello ananda,

you have to create a web application for your client then.

try writing an HTTPServlet that will create your EJB

instance and invoke a method defined in your EJB thru the

interface. deploy your servlet and access it thru your

browser.

here's a link to a code sample for a web client.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/EJB5.html

regards

jo

Former Member
0 Kudos

I am asking for the simple .java program which will contain main() method within which i will call EJB after going through JNDI lookup.

Please suggest

Thanks

ananda

Former Member
0 Kudos

hello ananda,

the answer was in the link already.

here's the application client side code sample.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/EJB4.html


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class TestClient {

  public static void main(String[] args) {

    try {
      Context initial = new InitialContext();
      Context myEnv = 
        (Context)initial.lookup("java:comp/env");
      //lookup for you interface
      Object objref = myEnv.lookup("ejb/TestEJB");
      //narrow to your Home interface
      MyEJBHome home = 
        (MyEJBHome )PortableRemoteObject.narrow(objref, 
                            MyEJBHome.class);
      //create your enterprise bean
      MyEnterpriseBean entBean = home.create();
      
      //invoke your business methods as defined in your
      //enterprise bean interface
      entBean.businessMethod();

      //e.g. if you have a sayHello():String method
      String resul = entBean.sayHello();
      System.out.println("From My Ent EJB:" + resul);

      System.exit(0);

    } catch (Exception ex) {
      System.err.println("Caught an unexpected exception!");
      ex.printStackTrace();
    }
  } 
} 

Former Member
0 Kudos

I which deployment descriptor which section I have to specify TestEJB.

Also how to run the application.

Will I require deploy tool for that ?

Thanks

ananda

Former Member
0 Kudos

hello anandra,

the answer is also in the link.

The MyEnterpriseBean, MyEJBHome, TestEJB and TestClient

are just sample names. Change this to your actual

interfaces names.

You specify this reference in deploytool as follows.

- In the tree, select TestClient.

- Select the EJB Ref's tab and click Add.

- In the Coded Name field, enter ejb/TestEJB.

- In the EJB Type field, select Session.

- In the Interfaces field, select Remote.

- In the Home Interface field enter, MyEJBHome.

dont forget the packge name as well.

- In the JNDI Name field, select MyEnterpriseBean.

- Click OK

Former Member
0 Kudos

Thanks for some hints.I still have some doubts

1.Is this TestClent program is a plain java project ?

2.After TestClent program is written what exactly the steps should I follow ?

3.When I opened deploy tool what steps I have to follow to get the TestClient in the tree and run it.

4. what should be written in the <jbdi-name> tag inside ejb-j2ee-engine.xml file.

5.From where TestClient program is executed ?

Thanks

ananda

Former Member
0 Kudos

hello ananda,

>1.Is this TestClent program is a plain java project ?

i assume that you're already familiar with java.

the code line i posted for TestClient is where your main

method is. Copy those lines and save into a file named

TestClient.java, then compile it. (i think i don't have

to elaborate how to do this).

>2.After TestClent program is written what exactly the

>steps should I follow ?

when you have compiled your ejb interfaces i.e. your

enterprise bean, and your remote interface implementations

you have to deploy them to your j2ee engine. you have to

consult to your deploytool how to do this. are you using

any wizard for deployment or you're doing it manually?

>3.When I opened deploy tool what steps I have to follow

>to get the TestClient in the tree and run it.

the tree depends on your deploytool.

you only have to deploy it. you can't run it anyway.

it will be utilized by your client application instead.

>4. what should be written in the <jbdi-name> tag inside

>ejb-j2ee-engine.xml file.

<jbdi-name>? are you referring to jndi-name?

it should be your enterprise bean name...

>5.From where TestClient program is executed ?

from your pc...

i would suggest that you should go through the tutorial

article which i posted on my formal links. this will

give you an idea how...

regards

jo

Former Member
0 Kudos

hi jo.

i am acutally working on this with Ananda (from opposite sides of the globe - the miracles of globalization!). i am finding your replies very helpful, but let me give you some more context. Ananda and I are pretty good with Java and we are reasonably good with servlet/jsp and EJB essentials. however, neither of us has any experience with J2EE application clients (as you can probably tell!). i have read the Sun tutorial sections you cited (I have the hard copy and also have the Sun app server installed, but just haven't had time to try the Tutorial exercise on my own.) But the key thing is, we're trying to do this in SAP, using the SAP DeployTool. Ananda and I have also read through the sections in SAP Help on writing a J2EE client (the sample program they give is pretty much same as in the Sun Tutorial) and on using the DeployTool. Unfortunately, as with much of the SAP Library, the entries are sometimes suggestive, sometimes obscure, and in the end don't provide a step-by-step recipe that we can follow. so we're fumbling and not yet successful in using the SAP DeployTool to deploy our app client. That's the context. Do you have any experience specifically with the SAP DeployTool?

Former Member
0 Kudos

hello randy, ananda,

okay, i now have an idea on your situation.

SAP deploytool is not generally used by developers in

deploying the applications they created. In fact, the

Netweaver Developer Studio has these tools already

available for you, e.g. generation of EJBs, assembling

and packagig of your EAR files, as well as deployment

of your archives to specific J2EE engines.

Are you using Netweaver Developer Studio? Or you are

using other development tools?

I think, SAP deploytool doesn't differ that much with

other J2EE deploytool. However, it has some extensions

to support Software Development Archive(sda) & Software

Component Archive(sca). Here's the reference related to

SAP Deploy Tool.

http://help.sap.com/saphelp_webas630/helpdata/en/9d/24f63def83c452e10000000a114084/content.htm

I will try to look over my notes if I have some visuals

that I could share to you related to this matter.

regards

jo

Former Member
0 Kudos

Hi All

I have solved the J2EE client application with main() calling EJB's after going through the SAP article "Accessing EJB Applications Using JNDI.pdf"

If anyone has queries let me know.

Thanks

Ananda