1 7 package org.jboss.tutorial.archive; 8 9 import java.net.URL ; 10 import java.util.Hashtable ; 11 import javax.naming.InitialContext ; 12 import org.jboss.ejb3.embedded.EJB3StandaloneDeployer; 13 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 14 15 21 public class Main 22 { 23 public static void main(String [] args) throws Exception 24 { 25 EJB3StandaloneBootstrap.boot(null); 26 27 EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer(); 28 URL archive = getArchiveURL(); 29 deployer.getArchives().add(archive); 30 31 deployer.setJndiProperties(getInitialContextProperties()); 34 35 deployer.create(); 36 deployer.start(); 37 38 InitialContext ctx = getInitialContext(); 39 CustomerDAOLocal local = (CustomerDAOLocal)ctx.lookup(CustomerDAOLocal.class.getName()); 40 CustomerDAORemote remote = (CustomerDAORemote)ctx.lookup(CustomerDAORemote.class.getName()); 41 42 System.out.println("----------------------------------------------------------"); 43 System.out.println("This is the archive deployed from: "); 44 System.out.print(" "); 45 System.out.println(archive); 46 47 int id = local.createCustomer("Gavin"); 48 Customer cust = local.findCustomer(id); 49 System.out.println("Successfully created and found Gavin from @Local interface"); 50 51 id = remote.createCustomer("Emmanuel"); 52 cust = remote.findCustomer(id); 53 System.out.println("Successfully created and found Emmanuel from @Remote interface"); 54 System.out.println("----------------------------------------------------------"); 55 56 deployer.stop(); 57 deployer.destroy(); 58 } 59 60 public static URL getArchiveURL() throws Exception 61 { 62 URL res = Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml"); 65 return EJB3StandaloneDeployer.getContainingUrlFromResource(res, "META-INF/persistence.xml"); 66 } 67 68 public static InitialContext getInitialContext() throws Exception 69 { 70 Hashtable props = getInitialContextProperties(); 71 return new InitialContext (props); 72 } 73 74 private static Hashtable getInitialContextProperties() 75 { 76 Hashtable props = new Hashtable (); 77 props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory"); 78 props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 79 return props; 80 } 81 } 82 | Popular Tags |