AddThis Social Bookmark Button

These are the steps for how to deploy ejb3 hellworld with jboss server.

  1.  Download jboss6 or any latest version  you want and extract it in any drive
    This is the download link download
    After that set the environment variable   like this
    Rigtclick on mycomputer=>properties=>advance=>Environment-variables
    In system variable click on new and then give the
    name  JBOSS_HOME
    Path    E:\jboss-as-distribution-6.0.0.Final\jboss-6.0.0.Final   (give that path where you have extracted that jboss zip file)

    Then press ok.
  2. Now in Eclipse  Rightclick=> project=>Choose ejbproject. The window will come like this

    Then click finish.
  3. Create one business interface EjbHelloWorld
    package com.bullraider.business.services;
    import javax.ejb.Remote;
    @Remote
    public interface EjbHelloWorld {
        public void hello(String text);
    }
    

    Create one class EjbHelloWorldBean
    package com.bullraider.business.services;
    import javax.ejb.Stateless;
    @Stateless
    public  class EjbHelloWorldBean implements EjbHelloWorld {
    
        public void hello(String hello) {
           System.out.println(hello);
            
        }
      }
    

    Then go to build path then configure build path then add external jar. Add jboss-ejb-api_3.1_spec.jar.You can get in client folder of jboss.
  4.  Then Rightclick on that project, click on export, choose  'ejb jar files'. Then one window will come. Click on browse and choose deploy folder of jboss like this

    Then click on finish
    This is the folder structure
  5. Create another java project "HelloUser-StandaloneClient"
     Here yor are using that business method you have created before. To access bussiness method first you have to add that HelloWorld_Services.jar which you have deployeed in default folder of server.
    You can go to build path then configure build path then add external jars. Go to default folder of joboss and add that jar HelloWorld_Services.jar, which you have deployed earlier. Or you can store that jar file in other folder and you can add it to build path.

    Other jar file you have to added is shown is picture

    Only jbosssx.jar you can get in lib folder and other from client folder of jboss.
     
  6. Create one class helloWorld-StandaloneClient
    package com.client.standalone;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import com.bullraider.business.services.EjbHelloWorld;
    
    public class EjbHelloWorldClient {
        public static void main(String[] args) {
        	
            Properties props = new Properties();
            props.put("java.naming.factory.initial", "org.jboss.naming.HttpNamingContextFactory" );
            props.put("java.naming.provider.url", "http://localhost:8080/invoker/JNDIFactory");
            props.put("java.naming.factory.url.pkgs", "org.jboss.naming");
            
            try {
                Context context = new InitialContext(props);
                           try {
                	                EjbHelloWorld helloWorld = (EjbHelloWorld)context.lookup("EjbHelloWorldBean/remote-com.bullraider.business.services.EjbHelloWorld");
                    helloWorld.hello("Hello World Ejb3.1");
                    
                } catch (NamingException e) {
                    System.out.println("couldn't look ");
                    e.printStackTrace();
                }
            } catch (NamingException e) {
                System.out.println("naming exception occoured");
                e.printStackTrace();
            } 
        }
    }
    

    This is the structure
  7. Go to jboss bin folder then click on run It'll start and after that run the HelloUserClient as java application
    this is the output