Tutorial : My Java World Eclipse + EJB + JBoss + Ant. Part 1
Now, I have been struggling in job finding world. I tested a lot, and all about J2EE blah blah and I completely failed. So, I decided to write this topic to record my understand about EJB. I will program EJB from scratch, without using any tools, or as less as possible.
First thing first after you installed JDK, you have to set variables in. Control Panel -> System -> Advance -> Environment Variables. Like the picture below.
After I have set the JAVA_HOME variable, the next thing is I have to create an EJB project.
You will get something like this
The Next thing is, you have to add J2EE library to the project. So, all the J2EE jars can be used in the project. The jars come from C:\Sun\SDK\lib <– according to my computer, which installed J2EE 5.04
In this project, I’m using Remote interface, because I wanted to show how the EJB can be connected via another J2EE container. So, After importing the j2EE jars, we have to create two interfaces which are Remote interface and Remote home interface. I’m creating com.noppanit.interfaces and com.noppanit.bean package. The bean package is for SessionBean.
HelloEJB.java is a Remote interface. It has to extend javax.ejb.EJBObject and has business method interface which throws RemoteException. Like this.
HelloEJBHome.java is a Remote home interface. It has to extend javax.ejb.EJBHome and has at least one creat(); method which return the Remote interface and throws RemoteException, CreateException.
The last one is SessionBean. It has to implement javax.ejb.SessionBean and has ejbActivate, ejbPassivate, ejbRemove, setSessionContext, and business methods.
The next thing is ejb-jar.xml. It’s a deployment descriptor. This xml file is for J2EE container, the file will be looked by the J2EE container. So, it can know that what type of this EJB is, and what is the name of this EJB, etc.
Now, the process of creating EJB is finished. The next thing is, we have to create build.xml, an ANT file. The ANT file is used for cleaning, compiling, deploying to application server. Actually, we can use Eclipse to do all these things, but I want to create this project from scratch.
After the deploying, jboss should see the EJB in its container and is ready to be used via JNDI.?? the next Chapter I will be using ordinary Java application client call the EJB. Actually, we must use web container to call the EJB.