1 7 package org.jboss.tutorial.dirbyresource; 8 9 import java.util.Hashtable ; 10 import javax.naming.InitialContext ; 11 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 12 import org.jboss.ejb3.embedded.EJB3StandaloneDeployer; 13 14 20 public class Main 21 { 22 public static void main(String [] args) throws Exception 23 { 24 EJB3StandaloneBootstrap.boot(null); 25 26 EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer(); 27 deployer.getDeployDirsByResource().add("META-INF/persistence.xml"); 28 29 deployer.setJndiProperties(getInitialContextProperties()); 32 33 deployer.create(); 34 deployer.start(); 35 36 InitialContext ctx = getInitialContext(); 37 CustomerDAOLocal local = (CustomerDAOLocal)ctx.lookup(CustomerDAOLocal.class.getName()); 38 CustomerDAORemote remote = (CustomerDAORemote)ctx.lookup(CustomerDAORemote.class.getName()); 39 40 System.out.println("----------------------------------------------------------"); 41 42 int id = local.createCustomer("Gavin"); 43 Customer cust = local.findCustomer(id); 44 System.out.println("Successfully created and found Gavin from @Local interface"); 45 46 id = remote.createCustomer("Emmanuel"); 47 cust = remote.findCustomer(id); 48 System.out.println("Successfully created and found Emmanuel from @Remote interface"); 49 System.out.println("----------------------------------------------------------"); 50 51 deployer.stop(); 52 deployer.destroy(); 53 } 54 55 public static InitialContext getInitialContext() throws Exception 56 { 57 Hashtable props = getInitialContextProperties(); 58 return new InitialContext (props); 59 } 60 61 private static Hashtable getInitialContextProperties() 62 { 63 Hashtable props = new Hashtable (); 64 props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory"); 65 props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 66 return props; 67 } 68 } 69 | Popular Tags |