« May 2008 | Main | July 2008 »

June 2008 Archives

June 10, 2008

Introduction to Enterprise JavaBeans 3.0 - for JDeveloper 10.1.3.3


Introduction to Enterprise JavaBeans 3.0 - for JDeveloper 10.1.3.3



When you are reading the Introduction to Enterprise JavaBeans 3.0 in otn.oracle.com you will find that there is no step by step guidance to put the code in JDeveloper.



The version of JDeveloper I am using is 10.1.3.3 and the files that I am running with only Session Bean and its simple client.


 

For CalculateEJB.java:



import javax.ejb.Remote;



@Remote

public interface CalculateEJB {

    String incrementValue();

}



For CalculateEJBLocal.java:


import javax.ejb.Local;


@Local

public interface CalculateEJBLocal {

}



For CalculateEJBBean.java:


import javax.ejb.Stateless;


@Stateless(name="CalculateEJB")

public class CalculateEJBBean implements CalculateEJB, CalculateEJBLocal {

    public CalculateEJBBean() {

    }

   

    int value = 0;

    public String incrementValue()

    {

        value++;

        return "value incremented by 1";

    }


}



At last, for the simple client:


import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;


public class CalculateEJBClient {

    public static void main(String [] args) {

        try {

            final Context context = getInitialContext();

            CalculateEJB calculateEJB =   

                   (CalculateEJB)context.lookup("CalculateEJB");

            // Call any of the Remote methods below to access the EJB

            System.out.println( calculateEJB.incrementValue(  ) );

        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }


    private static Context getInitialContext() throws NamingException {

        // Get InitialContext for Embedded OC4J

        // The embedded server must be running for lookups to succeed.

        return new InitialContext();

    }

}


 


Complete sample download.

About June 2008

This page contains all entries posted to Ming Man Chan's Blog in June 2008. They are listed from oldest to newest.

May 2008 is the previous archive.

July 2008 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle