Question: Java

Ads

 
 
 

Share on Google+Share on Google+

bala
Java
2 Answer(s)      8 years ago
Posted in : EJB
Ads
View Answers

July 17, 2008 at 12:49 PM


Here i am attaching a simple EJB3.0 application on JBoss Server.

Just follow the following steps
1. File->New->Other->EJB->EJB Project or File->New->EJB->EJB Project then give a name to your project and choose the default settings.
(Choose target runtime click on New button and configure JBoss Server)
2. It will create src folder and ejbModule by default choose it later you can change.
3. Write a sample interface named as Calculator.java
4. Write SesssionBean named as CalculatorBean
5. Write your client class named as CalculatorClient.java

here is my full running code
//***************************************

Calculator.java

/**
*
*/
package com.hcl.ejb.iface;

/**
* @author Administrator
*
*/
public interface Calculator {
public int add(int a,int b);
public float mul(float a,float b);

}
//***************************************
CalculatorLocal.java

package com.hcl.ejb.sessionface;
import com.hcl.ejb.iface.*;
import javax.ejb.Local;

@Local
public interface CalculatorLocal extends Calculator{

}
//***************************************

CalculatorRemote.java

package com.hcl.ejb.sessionface;
import com.hcl.ejb.iface.*;
import javax.ejb.Remote;

@Remote
public interface CalculatorRemote extends Calculator{

}

//***************************************

CalculatorBean.java

package com.hcl.ejb.session.bean;

import com.hcl.ejb.sessionface.CalculatorLocal;
import com.hcl.ejb.sessionface.CalculatorRemote;
import javax.ejb.Stateless;

public @Stateless class CalculatorBean implements CalculatorLocal, CalculatorRemote{

public int add(int a,int b){
return a+b;
}
public float mul(float a,float b){
return a+b;
}
}

//***************************************

CalculatorClient.java

/**
*
*/
package com.hcl.ejb.client;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.hcl.ejb.iface.*;
import com.hcl.ejb.sessionface.*;
import com.hcl.ejb.session.bean.*;

/**
* @author Administrator
*
*/
public class CalculatorClient {

/**
*
*/
public CalculatorClient() {
// TODO Auto-generated constructor stub
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Properties prop=new Properties();
prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.provider.url","jnp://localhost:1099";);
prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
InitialContext ctx=new InitialContext(prop);
System.out.println("111");
Calculator cal=(Calculator)ctx.lookup("CalculatorBean/remote");
System.out.println("222");
System.out.println("add: = "+cal.add(10,20));
System.out.println("mul: = "+cal.mul(10.5f,20.5f));

}catch(NamingException ne){
ne.printStackTrace();
}
}

}


deploy the project on JBoss and run it will run.


July 21, 2008 at 10:01 PM


thank So much , Tell me how to use in struts program , to invoke database in struts by using ejb

Ads









Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
Tutorials   
Java Spring Hibernate Struts Training email verification in e commerce application email verification in e commerce application EJB interceptors Demo How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ??? RUNNING EJB PROGRAMS Issue when deploying mdb jar in weblogic Weblogic8 server problem login module program login module program jsp project Lookup failed in SessionBean mahesh How to display single row from sql server 2005 how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL Stateless Bean Error Stateless Session Bean Example Error EJB Deployment how to create a simple ejd session bean and how to do project setup Ejb Module Ejb Module EJB JSP - Checkbox remain checked although checked values should depend on values stored in a stateful session bean Session Bean Example Bean RMI ejb ejb webservices message driven bean example entity bean j2ee example programs Rose India Stateless Session Bean Example Question Coding with Ejb EJB with NetBeans Run a simple EJB code Run a simple EJB code Used Handicap Vans Issue in Stateless session bean example ejb ejb methods can be invoked by the container on a stateless session bean session Join problem with JPA Criteria Builder About Web-Logic Abut Deploying and Developing Web-Logic in JDK1.5 version to run the EJB managing the transactions Pagination DataGrid without DataBase Many To Many annotation in ejb use of ejb 3.0

Ads

 
Advertisement null

Ads