Creating J2EE application in IntelliJ Idea 6.0 - EJB3/JBOSS +Ajax. Tutorial. Part 1

Hello my readers. Today I want to show how to create Ajax application in IntelliJ Idea 6. It will use EJB3 contained on JBOSS application server.

Setup JBOSS

How to setup JBOSS read here How to save several hours on setup JBOSS+EJB3

Create EJB3 module

File->New Project...

 

Type Name: AjaxProject and press Next button until you will see such dialog: Choose Create/configure multi-module project.

Press Finish.

<!--googleAd--> You will see Project structure dialog. Expand Project "Ajax project" -> Right press on Modules -> Add module:

Choose Ejb Module:

 

Press Next ->Type ejb3:

Press next until you see Deployment Descriptors-> Add application Server specific descriptor...-> Choose JBoss Server:

We want to use Log4j so you should on Tab Dependencies press Add...->Choose Application server library...->

 

Choose your Application server-> Attach Classes...-><path of JBoss>\server\name of server configuration(all)\lib\log4j.jar

Press Ok-> Check JBoss

Press Finish.

Let's create Session bean. Right click on ejb3-> New -> Session Bean:

Type Name: Logger; package: sample

Press button Change EJB Classes->check Local interface check box-> Ok

We need only Local Interface in our simple example.

In LocalLogger interface such code:

package sample;

import javax.ejb.EJBLocalObject;

public interface LocalLogger extends EJBLocalObject {

public String Log(String msg) throws Exception;

}

LocalLoggerHome:

package sample;

import javax.ejb.EJBLocalHome;

import javax.ejb.CreateException;

 

public interface LocalLoggerHome extends EJBLocalHome {

sample.LocalLogger create() throws CreateException;

}

 

LoggerBean:

package sample;

 

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import org.apache.log4j.Logger;

public class LoggerBean implements SessionBean {

 

 

private static final Logger log = Logger.getLogger( "sample.LoggerBean");

public String Log(String msg)

{

try{

log.info(msg);

return "logged";

}

catch(Exception e)

{

log.error(e);

return "error:"+e.toString();

}

}

 

public LoggerBean() {}

public void ejbCreate() {}

public void ejbRemove() {}

public void ejbActivate() {}

public void ejbPassivate() {}

public void setSessionContext(SessionContext sc) {}

}

 

At the end we should assign Local JNDI Name for EJB

Right click on LoggerEJB->Edit...

Jboss Server tab-> Local JNDI Name: logger

In the next Part we will create web client

 

Comments

You can use simple HTML-formatting tags(like <b>, <ul>, <code> and others)