Search code examples
jakarta-eedeploymentpayara

deploy to Payara from within application


I would like to know if its possible for java enterprise application to deploy another application to payara server. I found something in the Documentation.

import fish.payara.micro.BootstrapException;
import fish.payara.micro.PayaraMicro;
import fish.payara.micro.PayaraMicroRuntime;
import java.io.File;

public class EmbeddedPayara{
    public static void main(String[] args) throws BootstrapException{
        File war = new File("/home/user/deployments/");
        PayaraMicroRuntime instance = PayaraMicro.bootstrap();
        instance.deploy(war);
    }
}

But this applies to the payara micro. And I cant find any class called PayaraMicro to import. Is there a way to do it in Payara full ?


Solution

  • There's no official way to do this in Payara Server although it's possible to do it.

    There's GlassFish API which can be used from a deployed application to deploy other apps. See Deployer Javadoc. Nothing has changed in Payara Server so it should work also with Payara Server.

    Another option is to use Cargo project deployer, which also supports Payara Server (using the GlassFish deployer). It also works outside of Payara Server, in any Java SE application, but is more complicated to set up.

    Another option is to use the raw REST endpoint provided by the Admin Console, which is used by the asadmin tool and Cargo Deployer. You wouldn't need any external dependency but it's not very documented which resource to access. Here's the docs, here's the code of the DeployCommand which describes which parameters it accepts, and here's a path to the deploy endpoint: http://localhost:4848/management/domain/applications/deploy. If you paste the link to a browser, it will give an HTML frontend to test with. If you send a post request with accept type JSON, it will return a response in JSON format (success/failure)