JBoss+Eclipse安装配置开发EJB3.0

1.下载jboss安装包jems-installer-1.2.0.BETA2.jar进行图形界面安装,
安裝時必需选择 ejb3-clustered [ 這很重要 ]。
不需要jboss-4.0.4.GA.zip

2。下载JBossIDE-1.6.0.GA-ALL,也就是eclipse的插件,copy到eclipse下。
注意一点:eclipse-SDK-3.2始终无法创建create a jboss cofiguration,如果用
eclipse-SDK-3.1就没问题。

3。写个测试程序:

HelloWorld HelloWorldBean
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
 public String echo(String msg) ;
}

import javax.ejb.Stateless;

public @Stateless class HelloWorldBean implements HelloWorld {
 public String echo(String msg) {
  System.out.println("Joeyta try Hello World.");
  return msg;
 }
}

HelloWorldClient运行
package com;
import java.util.Properties;

import javax.naming.InitialContext;
public class HelloWorldClient
{
   public static void main(String[] args) throws Exception
   {
   
    Properties properties = new Properties();
       properties.put("java.naming.factory.initial",
                       "org.jnp.interfaces.NamingContextFactory");
       properties.put("java.naming.factory.url.pkgs",
                       "org.jboss.naming:org.jnp.interfaces");
       properties.put("java.naming.provider.url", "jnp://localhost:1099");
       properties.put("jnp.disableDiscovery", "true");

   
      InitialContext ctx = new InitialContext(properties);
      HelloWorld helloWorld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
      System.out.println(helloWorld.echo("Hello World, Joeyta"));
   }
}

ant build.xml进行deploy
<?xml version="1.0"?>
<project name="JBoss" default="run.HelloWorldClient" basedir=".">
 <property environment="env" />
 <property name="jboss.home" value="E:/Jboss/jboss-4.0.4.GA/jboss-4.0.4.GA" />
 <property name="classes.dir" value="bin" />
 <path id="classpath">
  <fileset dir="${jboss.home}/client">
   <include name="**/*.jar" />
  </fileset>
  <pathelement location="${classes.dir}" />
 </path>
 
 <target name="clean">
  <delete file="${basedir}/HelloWorld.jar" />
  <delete file="${jboss.home}/server/default/deploy/HelloWorld.jar" />
 </target>
  
 <target name="ejbjar" >
  <jar jarfile="HelloWorld.jar">
   <fileset dir="${classes.dir}">
    <include name="com/*.class" />
   </fileset>
  </jar>
  <copy file="HelloWorld.jar " todir="${jboss.home}/server/default/deploy" />
 </target>
 <target name="run.HelloWorldClient" depends="ejbjar">
  <java classname="com.HelloWorldClient" fork="yes" dir=".">
   <classpath refid="classpath" />
  </java>
 </target>
</project>

写一个Test.jsp:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.HelloWorld, javax.naming.*, java.util.Properties"%>
<%
  Properties props = new Properties();
  props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  props.setProperty("java.naming.provider.url", "localhost:1099");
  props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); 

  InitialContext ctx;
  try {
   ctx = new InitialContext(props);
   HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
   out.println(helloworld.echo("Test"));
  } catch (NamingException e) {
   out.println(e.getMessage());
  }
%>
如果客户端和jboss运行在同一个jvm,不需要传入props
直接写成:
 try {
   InitialContext  ctx = new InitialContext();
   HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
   out.println(helloworld.echo("Test"));
  } catch (NamingException e) {
   out.println(e.getMessage());
  }
加上一个空的WEB-INF/web.xml
进行根目录,输入:jar cvf  Test.war *  打包成war形式,放在jboss下就可以访问了http://localhost:8080/Test/Test.jsp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值