Definition
How to perform deployments to a remote GlassFish 6.x and later containers, as well as to recent versions of Payara
Explanation
All Cargo GlassFish and Payara deployers use the GlassFish / Payara asadmin behind the scenes, and all of them set the cargo.hostname as the target host.
As a result, all GlassFish and payara Installed Local Deployers can actually be used to perform remote deployments, the main "downside" being that this requires the GlassFish / Payara container ZIP file to be downloaded (which can be done transparently using an installer).
Here is an example code for the users of the Java API:
Installer installer = new ZipURLInstaller(
"https://download.eclipse.org/ee4j/glassfish/glassfish-6.2.5.zip",
"target/downloads", "target/extracts");
installer.install();
InstalledLocalContainer container = new GlassFish6xInstalledLocalContainer(
new GlassFish6xStandaloneConfiguration("target/glassfish6x"));
container.setHome(installer.getHome());
// Set the hostname to a running, remote GlassFish 6.0 instance
// for the GlassFish6xInstalledLocalDeployer to perform a remote deployment
container.getConfiguration.setProperty(GeneralPropertySet.HOSTNAME, "10.0.2.15");
// Instruct the GlassFish asadmin to upload the file to the remote server
container.getConfiguration.setProperty(
GlassFishPropertySet.DEPLOY_ARG_PREFIX + "remoteUpload", "--upload=true");
DeployableFactory factory = new DefaultDeployableFactory();
WAR war = factory.createDeployable(container.getId(), "path/to/my.war",
DeployableType.WAR);
// Create dummy local configuration and deploy remotely
container.getConfiguration().configure(container);
Deployer deployer = new GlassFish6xInstalledLocalDeployer(container);
deployer.deploy(war);
Here is an example Maven 3 plugin configuration, where one can use the Maven Artifact Installer:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>${cargo.plugin.version}</version>
<configuration>
<container>
<containerId>glassfish6x</containerId>
<artifactInstaller>
<groupId>org.glassfish.main.distributions</groupId>
<artifactId>glassfish</artifactId>
<version>6.2.5</version>
</artifactInstaller>
</container>
<configuration>
<home>${project.build.directory}/glassfish6x-home</home>
<properties>
<cargo.hostname>10.0.2.15</cargo.hostname>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.glassfish.admin.port>4848</cargo.glassfish.admin.port>
<cargo.remote.username>admin</cargo.remote.username>
<cargo.remote.password>changeme</cargo.remote.password>
<cargo.glassfish.deploy.arg.remoteUpload>--upload=true</cargo.glassfish.deploy.arg.remoteUpload>
</properties>
</configuration>
</configuration>
</plugin>
Please note that the above deployer requires its "dummy" local configuration to exist. You hence need to run it with:
mvn cargo:configure cargo:deploy