package testdeployment; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; import java.util.Enumeration; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.enterprise.deploy.spi.Target; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; import org.jvnet.hk2.annotations.Service; import org.glassfish.api.ActionReport; import org.glassfish.api.ActionReport.ExitCode; import org.glassfish.deployment.client.DFDeploymentProperties; import org.glassfish.deployment.client.DFDeploymentStatus; import org.glassfish.deployment.client.DFProgressObject; import org.glassfish.deployment.client.DeploymentFacility; import org.glassfish.deployment.client.DeploymentFacilityFactory; import org.glassfish.deployment.client.ServerConnectionIdentifier; import org.jvnet.hk2.component.Habitat; import org.jvnet.hk2.annotations.Inject; @Service(name="testdeploy") public class TestDeploy implements AdminCommand{ @Inject Habitat habitat; public void execute(AdminCommandContext context){ ActionReport report = context.getActionReport(); testDeploy(); report.setMessage("After TestDeploy"); report.setActionExitCode(ExitCode.SUCCESS); } public void testDeploy() { String APP_NAME = "servletonly"; DeploymentFacility df = DeploymentFacilityFactory.getDeploymentFacility(); ServerConnectionIdentifier sci = new ServerConnectionIdentifier(); sci.setHostName("localhost"); sci.setHostPort(4848); // 8080 for the REST client sci.setUserName("admin"); sci.setPassword("adminadmin"); df.connect(sci); // File archive = new File("C:\\tim\\asgroup\\dev-9p-fcs\\glassfish\\appserv-tests\\devtests\\deployment\\build\\servletonly.war"); // File archive = new File("/Users/Tim/asgroup/v3/warWithPlan/servletonly-portable.war"); // File plan = new File("/Users/Tim/asgroup/v3/warWithPlan/servletonly-deployplan.jar"); File archive = new File("path to app"); File plan = new File("path to plan"); DFDeploymentProperties options = new DFDeploymentProperties(); options.setForce(true); options.setUpload(true); options.setName(APP_NAME); options.setExternallyManaged(true); options.setArchiveName("MyApp"); Properties props = new Properties(); props.setProperty("keepSessions", "true"); options.setProperties(props); DFProgressObject prog = df.deploy( new Target[0] /* ==> deploy to the default target */, archive.toURI(), plan.toURI(), options); DFDeploymentStatus ds = prog.waitFor(); if (ds.getStatus() == DFDeploymentStatus.Status.FAILURE) { System.out.println("Deployment Failure"); } } }