import org.glassfish.embeddable.*; import org.glassfish.embeddable.web.*; import java.io.*; import java.net.*; import java.net.*; import java.io.*; public class EJBTest { public static void main(String... args) throws Exception { File installRoot = new File(args[0]); BootstrapProperties bootstrapProperties = new BootstrapProperties(); bootstrapProperties.setInstallRoot(installRoot.getCanonicalPath()); GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap(bootstrapProperties); GlassFishProperties gfProps = new GlassFishProperties(); gfProps.setProperty("org.glassfish.embeddable.autoDelete", "false"); // set autodelete to false. gfProps.setConfigFileReadOnly(false); // make sure the domain.xml is written back. //gfProps.setInstanceRoot(instanceRoot); String domain = args[1]; gfProps.setConfigFileURI(domain); GlassFish glassfish = gfRuntime.newGlassFish(gfProps); glassfish.start(); Thread.sleep(1000); glassfish.stop(); Thread.sleep(10); glassfish.start(); Deployer deployer = glassfish.getDeployer(); String appName = deployer.deploy(new File(args[2])); String url = "http://localhost:8080/" + "ejb-ejb31-embedded-ejbwinwar-web/mytest"; System.out.println("invoking webclient servlet at " + url); URL u = new URL(url); HttpURLConnection c1 = (HttpURLConnection)u.openConnection(); int code = c1.getResponseCode(); InputStream is = c1.getInputStream(); BufferedReader input = new BufferedReader (new InputStreamReader(is)); String line = null; while((line = input.readLine()) != null) System.out.println(line); if(code != 200) { throw new RuntimeException("Incorrect return code: " + code); } System.out.println("Successfully deployed [ " + appName + " ]"); System.out.println("Press any key to exit."); new BufferedReader(new InputStreamReader(System.in)).readLine(); glassfish.dispose(); } }