采用eclipse+Jboss开发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
package com;

import javax.ejb.Stateless;

@Stateless
public class HelloWorldBean implements HelloWorldRemote, HelloWorldLocal {
 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>
 



你可能感兴趣的:(java,eclipse,ant,jboss,ejb)