• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I want to read about running an ejb app

 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to start. I d/led Sun's J2EE w/ an app server. It comes with 3 demos. I compiled them and failed to run them. Anyway, I care less about those demos. I just want to run a simple Hello world demo just to get a feel of what ejb however I don't know where to start. Can someone please help me. I am reading "Mastering EJB" and it claims that they want to stay Application Server neutral can it contains simple codes that I don't know how I should run them. Can somebody forward me some links or instructions to get me started? Many thanks.
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//Hello.java
package examples;
public interface Hello extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}
//HelloLocal.java
package examples;
public interface HelloLocal extends javax.ejb.EJBLocalObject
{
public String hello();
}

//HelloHome.java
package examples;
public interface HelloHome extends javax.ejb.EJBHome
{
Hello create() throws java.rmi.RemoteException, javax.ejb.CreateException;
}
//HelloLocalHome.java
package examples;
public interface HelloLocalHome extends javax.ejb.EJBLocalHome
{
HelloLocal create() throws javax.ejb.CreateException;
}
//HelloBean.java
package examples;
public class HelloBean implements javax.ejb.SessionBean {
private SessionContext ctx;
//
// EJB-required methods
//
public void ejbCreate() {
System.out.println("ejbCreate()");
}
public void ejbRemove() {
System.out.println("ejbRemove()");
}
public void ejbActivate() {
System.out.println("ejbActivate()");
}
public void ejbPassivate() {
System.out.println("ejbPassivate()");
}
public void setSessionContext(javax.ejb.SessionContext ctx) {
this.ctx = ctx;
}
//
// Business methods
//
public String hello() {
System.out.println("hello()");
return "Hello, World!";
}
}
//ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" " http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient {
public static void main(String[] args) throws Exception {

Properties props = System.getProperties();
Context ctx = new InitialContext(props);

Object obj = ctx.lookup("HelloHome");

HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

Hello hello = home.create();

System.out.println(hello.hello());

hello.remove();
}
}
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the above 6 files and I will jar up the server site classes. How do I run them? I have started the Sun Application server and I don't know what to do, can someone please help me?
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi edward,
I am also a starter and i was able to run the appplication after some difficulty. I am also studying Ed Roman's book and as you had mentioned it does not mention how to run it any particular web server.
Since you have now written the source files, you would now have to deploy the files in your application server or to be more precise deploy the Enterprise java bean and then run the client:-)
Since you already have the sun application server I would suggest you to deploy the application using the deploy tool utility provided with sun application server.
To know how to use the deploy tool, you can go through the J2EE 1.3 tutorials in the sun web site. the link is
http://java.sun.com/j2ee/1.3/download.html#tutorial
REMEMBER you will have to download tutorials for J2EE 1.3 , BUT have J2EE 1.4 to run the deploy tool. You would also encounter certain other small problems. Please follow the link given below to see the problems I had faced when I tried to deploy the application in Sun application server using the J2EE 1.3 tutorials
http://www1.coe.neu.edu/~hari/html/tutorials/java/ejb/example/example.html
Hope this helps!! GOOD LUCK :-)
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, I can try your hints out. Something that I found interesting is that your app server won't work until you unplug your internet. As far as I know, your browser doesn't use localhost port 80, unless you have a webserver on, the port 80 should be free and if you do have a webserver on, port 80 will be in use even the computer is unplugged from the internet. Anyway, I'll keep trying.
When did you start studying and when are you planning to write the exam?
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started studying from october 1, and I have fixed my exam date on oct 30..Hopefully I finish studying before that :-)
hari
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Study 30 days and you will be ready? quite smart. Are you studying full time?
BTW, I ran into the problem of not able to start the application server which uses port 1043. I tried to shutdown most of the useless process (which I have no clue what they are) and the port 1043 is available again and I then can start the application server. Anyway, if disconnecting the computer from internet works for you, that's good.
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And edward my app server works perfectly, It is just the deploy tool that hangs wgen I do an operation through it ..like trying to deploy an application on the application server :-(
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic