EJB3 + GlassFish version 3

개발 환경 NetBeans 6.9.1
 
step 1: GlassFish v3에 해당하는 EJB 추가
쓰다
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.helloworld.test;

import javax.ejb.EJBException;

/**
 *
 * @author liuqing
 */
public interface IHelloWorld {

    public String sayHelloWorld(String str) throws EJBException;

}

 
step 2: 로컬 및 원격 인터페이스 추가
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.helloworld.test;

import javax.ejb.Local;

/**
 *
 * @author liuqing
 */
@Local
public interface ILocalHelloWorld extends IHelloWorld{


}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.helloworld.test;

import javax.ejb.Remote;

/**
 *
 * @author liuqing
 */
@Remote
public interface IRemoteHelloWorld extends IHelloWorld{

}

 
step 3: 추가 구현
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.helloworld.test.impl;

import com.helloworld.test.ILocalHelloWorld;
import com.helloworld.test.IRemoteHelloWorld;
import javax.ejb.EJBException;
import javax.ejb.Stateless;

/**
 *
 * @author liuqing
 */
@Stateless
public class HelloWorldImplBean implements ILocalHelloWorld,IRemoteHelloWorld{

    public String sayHelloWorld(String str) throws EJBException {
        return "Hello ,My name is EJB Server : " + str;
    }

}

 
step 4: 번호 테스트 클래스
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.test;

import com.helloworld.test.IRemoteHelloWorld;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author liuqing
 */
public class Test {

    public static void main(String args[]) throws Exception {

        Properties props = new Properties();
        
        props.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
        props.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
        props.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
        //host
        props.put("org.omg.CORBA.ORBInitialHost", "localhost");
        //EJB Port
        props.put("org.omg.CORBA.ORBInitialPort", "3700");
        Context ctx = new InitialContext(props);
        ctx.lookup("com.helloworld.test.IRemoteHelloWorld");
        IRemoteHelloWorld hello = (IRemoteHelloWorld)ctx.lookup(IRemoteHelloWorld.class.getName());
        System.out.println(hello.sayHelloWorld("Welcome to GlassFish v3"));
    }

}

   
final 추가 중*.jar 가방
 
glassfish-naming.jar//JNDI 패키지 추가
gf-client-module.jar//클라이언트 모듈 패키지
gf-ejb-connector.jar//연결 jb 패키지
gf-client.jar      
 
실행 결과
 
init:
deps-jar:
compile-single:
run-main:
Nov 19, 2010 3:32:39 PM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
Hello ,My name is EJB Server : Welcome to GlassFish v3
BUILD SUCCESSFUL (total time: 7 seconds)

좋은 웹페이지 즐겨찾기