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
PayaraMicroclass lets you spin up an embedded Payara instance, whilePayaraMicroRuntimegives 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.
- Use
- 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
asadmincommand-line tool: Execute deployment commands viaProcessBuilderin your application.
内容的提问来源于stack exchange,提问作者František Jeřábek
相关产品推荐
相关产品推荐

