1 7 package org.jboss.tutorial.archivebyresource; 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.getArchivesByResource().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 System.out.println("We will search for all archives with META-INF/persistence.xml to deploy them."); 42 System.out.println(" "); 43 44 int id = local.createCustomer("Gavin"); 45 Customer cust = local.findCustomer(id); 46 System.out.println("Successfully created and found Gavin from @Local interface"); 47 48 id = remote.createCustomer("Emmanuel"); 49 cust = remote.findCustomer(id); 50 System.out.println("Successfully created and found Emmanuel from @Remote interface"); 51 System.out.println("----------------------------------------------------------"); 52 53 deployer.stop(); 54 deployer.destroy(); 55 } 56 57 public static InitialContext getInitialContext() throws Exception 58 { 59 Hashtable props = getInitialContextProperties(); 60 return new InitialContext (props); 61 } 62 63 private static Hashtable getInitialContextProperties() 64 { 65 Hashtable props = new Hashtable (); 66 props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory"); 67 props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 68 return props; 69 } 70 } 71 | Popular Tags |