// instance environment for this server
InstanceEnvironment env =
ApplicationServer.getServerContext().getInstanceEnvironment();
// sets the type of the archive being deployed
DeployableObjectType type = null;
if ( FileUtils.isEar(archive) ) {
type = DeployableObjectType.APP;
} else if ( FileUtils.isJar(archive) ) {
type = DeployableObjectType.EJB;
} else if ( FileUtils.isWar(archive) ) {
type = DeployableObjectType.WEB;
} else if ( FileUtils.isRar(archive) ) {
type = DeployableObjectType.CONN;
}
// constructs a deploy request with the given type
DeploymentRequest req =
new DeploymentRequest(env, type, DeploymentCommand.DEPLOY);
// sets the archive that needs to be deployed
req.setFileSource(archive);
// application is registered with the name of the
// archive without extension
String fileName = archive.getName();
int dotIdx = fileName.indexOf(fileName);
String regName = fileName.substring(0, dotIdx);
req.setName(regName);
// sets the web context root
if (type.isWEB()) {
req.setContextRoot(regName);
}
// redeploys the app if already deployed
req.setForced(true);