You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java EE应用能否向Payara Server部署其他应用?

Can a Java Enterprise App Deploy Another App to Payara Server?

Absolutely! You can programmatically deploy additional applications to Payara Server, and Payara Micro makes this straightforward with its embedded API. The code snippet you referenced is a great starting point—here's a complete, working example along with clear explanations:

Working Code Example

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 {
        // Point to a directory containing WAR files (or a single WAR file)
        File deploymentDir = new File("/home/user/deployments/");
        
        // Bootstrap Payara Micro and deploy all apps in the specified directory on startup
        PayaraMicroRuntime instance = PayaraMicro.bootstrap()
                .setDeploymentDir(deploymentDir)
                .start();
        
        // Optional: Deploy an additional app at runtime *after* the server is running
        File anotherWar = new File("/home/user/new-app.war");
        instance.deploy(anotherWar);
    }
}

Key Breakdown

  • Payara Micro API: The PayaraMicro class lets you spin up an embedded Payara instance, while PayaraMicroRuntime gives you control over the running server—including on-demand app deployment.
  • Deployment Flexibility:
    • Use setDeploymentDir() to deploy multiple apps in one go when starting the server.
    • Use deploy(File) on the runtime instance to add new applications at any time after the server is live.
  • Dependencies: To use this, add the Payara Micro dependency to your project. For Maven, include this in your pom.xml:
    <dependency>
        <groupId>fish.payara.extras</groupId>
        <artifactId>payara-micro</artifactId>
        <version>6.2024.6</version> <!-- Use the latest stable version -->
        <scope>provided</scope>
    </dependency>
    

Additional Options for Full Payara Server

If you're working with a full (non-Micro) Payara Server instance, you can also deploy apps programmatically using:

  • The Admin REST API: Call server endpoints to deploy/undeploy apps from your Java code.
  • The asadmin command-line tool: Execute deployment commands via ProcessBuilder in your application.

内容的提问来源于stack exchange,提问作者František Jeřábek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:20:16