import java.io.*; import java.net.URL; import java.net.URLClassLoader; import java.util.logging.Level; import org.glassfish.embeddable.*; import org.glassfish.embeddable.web.*; public class Test_cacao { public static void main(String args[]) throws Exception { BootstrapProperties bsProps = new BootstrapProperties(); String gfInstall = "/usr/lib/cacao/ext/gfish"; // String gfInstall = "/glassfish3/glassfish"; System.out.println("Using GlassFish install root at " + gfInstall); bsProps.setInstallRoot(gfInstall); GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap(bsProps); GlassFishProperties gfProps = new GlassFishProperties(); gfProps.setInstanceRoot("/var/cacao/instances/default/configs/gf"); // gfProps.setInstanceRoot("/glassfish3/glassfish/domains/domain1"); System.out.println("Using GlassFish instance root at " + gfProps.getInstanceRoot()); GlassFish glassfish = gfRuntime.newGlassFish(gfProps); glassfish.start(); WebContainer wc = glassfish.getService(WebContainer.class); wc.setLogLevel(Level.INFO); URL[] urls = new URL[1]; urls[0] = (new File("/var/tmp/cacao/toto.jar")).toURI().toURL(); URLClassLoader classLoader = new URLClassLoader(urls, Test_cacao.class.getClassLoader()); //test loadA(classLoader); Thread.currentThread().setContextClassLoader(classLoader); String war = "/var/cacao/instances/default/configs/com.sun.cacao.webserver/cacao_gfish_test.war"; System.out.println("---> Deploying war at " + war); Context context = wc.createContext(new File(war), classLoader); wc.addContext(context, "cacao_gfish_test"); System.out.println("---> War " + war + " deployed at cacao_gfish_test"); } private static void loadA(ClassLoader cl) { try { System.out.println("---> Loading TestCacaoList with " + cl.toString()); cl.loadClass("TestCacaoList"); System.out.println("---> Finish to load TestCacaoList with " + cl.toString()); } catch (Exception ex) { System.out.println("---> Cannot load TestCacaoList with " + cl.toString() + ": " + ex); throw new IllegalStateException(); } } }