private void launch() { try { GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); glassfish.start(); glassfish.getDeployer().deploy(new File(inputWar), deployProperties.getDeployOptions()); } catch (Throwable th) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Server was stopped.", th); System.exit(1); } }
private void undeploy() { if (deployedAppName != null) { try { deployer.undeploy(deployedAppName); } catch (Exception e) { _logger.warning("Cannot undeploy deployed modules: " + e.getMessage()); } } }
Deployer deployer = glassfish.getDeployer(); // Create a scattered web application. ScatteredArchive archive = new ScatteredArchive("testapp", ScatteredArchive.Type.WAR); // target/classes directory contains my complied servlets archive.addClassPath(new File("target", "classes")); // resources/sun-web.xml is my WEB-INF/sun-web.xml archive.addMetadata(new File("resources", "sun-web.xml")); // resources/MyLogFactory is my META-INF/services/org.apache.commons.logging.LogFactory archive.addMetadata(new File("resources", "MyLogFactory"), "META-INF/services/org.apache.commons.logging.LogFactory"); deployer.deploy(archive.toURI())
private void undeploy() { if (deployedAppName != null) { try { deployer.undeploy(deployedAppName); } catch (Exception e) { _logger.warning("Cannot undeploy deployed modules: " + e.getMessage()); } } }
String port = System.getenv("PORT"); GlassFishProperties gfProps = new GlassFishProperties(); gfProps.setPort("http-listener", Integer.parseInt(port)); GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(gfProps); glassfish.start(); Deployer deployer = glassfish.getDeployer(); File file = new File("YourSimpleMavenWebapplication.war"); deployer.deploy(file);
public void undeploy(String appName) { try { getDeployer().undeploy(appName); } catch (GlassFishException e) { log.error("Undeploy of " + appName + " failed", e); } }
//Start GF GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap(); GlassFish gf = gfRuntime.newGlassFish(); gf.start(); //Deploy application with EJBs Deployer deployer = gf.getService(Deployer.class); String deployedApp = deployer.deploy(new File(...), "--force=true"); //Create InitialContext Properties props = new Properties(); props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); InitialContext ic = new InitialContext(props); //Lookup EJBs ic.lookup(...) //Stop GF gf.stop(); gfRuntime.shutdown(); //CORBA stuck thread, have to kill it manually System.exit(0);
/** * Undeploys all deployed modules in reverse order. */ private void undeployModules() { try { Deployer deployer = glassFish.getDeployer(); while (!deployed.isEmpty()) { String applicationName = deployed.pop(); deployer.undeploy(applicationName); } } catch (GlassFishException exc) { throw new TestContainerException(exc); } }
private void deployWar(URI warUri) throws GlassFishException { Deployer deployer = glassFish.getDeployer(); String appName = deployer.deploy(warUri, "--name", getApplicationName(), "--contextroot", getContextRoot()); if (! getApplicationName().equals(appName)) { throw new RuntimeException("error deploying WAR"); } }
private void shutdownInternal() throws GlassFishException { if (glassFish != null) { glassFish.getDeployer().undeploy(getApplicationName()); glassFish.stop(); glassFish = null; } }
private void start() { try ( InputStream gpis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_glassfish.properties"); InputStream dpis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_deploy.properties"); InputStream wis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_application.war")) { GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.getProperties().load(gpis); URL url = this.getClass().getClassLoader().getResource("uber-jar_domain.xml"); if (url != null) { glassfishProperties.setConfigFileURI(url.toURI().toString()); } DeployProperties deployProperties = new DeployProperties(); deployProperties.load(dpis); GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); glassfish.start(); glassfish.getDeployer().deploy(wis, deployProperties.getDeployOptions()); } catch (Throwable th) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Server was stopped.", th); System.exit(1); } } }
public void undeploy(Archive<?> archive) throws DeploymentException { try { glassfish.getDeployer().undeploy(createDeploymentName(archive.getName())); } catch (Exception e) { throw new DeploymentException("Could not undeploy " + archive.getName(), e); } }
@RunWith(Arquillian.class) public class TestA { @Deployment(name = "x", managed = false) @TargetsContainer("manual_felix") public static Archive<?> deployment() { return ShrinkWrap.create.... } @ArquillianResource private ContainerController cc; @ArquillianResource private Deployer d; @Test @InSequence(1) public void start() { cc.start("manual_felix", new Config().add("frameworkProperties", "my-custom-properties-file")); d.deploy("x"); } @Test @InSequence(2) @OperatesOnDeployment("x") public void shouldDoSomethingInsideX() { // executes inside container in context of X } }
/** * Stops the given <tt>context</tt> and removes it from this * <tt>VirtualServer</tt>. */ public void removeContext(Context context) throws GlassFishException { try { Deployer deployer = Globals.getDefaultHabitat().getComponent(Deployer.class); deployer.undeploy(context.getContextPath()); } catch (Exception ex) { throw new GlassFishException(new ConfigException( "Context with context path " + context.getContextPath() + " cannot be removed from virtual server " + getID())); } }
public void deploy(Archive<?> archive) { try { ZipExporter exporter = archive.as(ZipExporter.class); File file = tmpFolder.newFile(archive.getName()); exporter.exportTo(file, true); final String appName = getDeployer().deploy(file); log.info("Application {} deployed as {}", archive.getName(), appName); } catch (Exception e) { throw new RuntimeException("Deployment failed", e); } }
tempFile.deleteOnExit(); StreamUtils.copyStream(stream, new FileOutputStream(tempFile), true); deployer.deploy(tempFile, "--name", PROBE_APPLICATION_NAME, "--contextroot", PROBE_APPLICATION_NAME); deployed.push(PROBE_APPLICATION_NAME);