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   //连接ejb 包

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值